Fatal error c1903 не удается восстановить после предыдущих ошибок остановка компиляции

I have a weird error when I compile my project on MSVC.

I am using Microsoft Visual Studio 15 2017 and I compile in c++17 (MSVC version 15.6.85.37198)

The code compiles on Clang and G++ but it gives me an error on MSVC.

I managed to reduce the code causing the error to the following snippet :

#include <cstddef>

struct Point {
    double x;
    double y;
    double z;
};

template<class... Ps>
void doSomething() {
    offsetof(Point, x);
}

int main() {
    doSomething();
}

It gives me the following error :

main.cpp(10): fatal error C1903: unable to recover from previous error(s); stopping compilation [buildexample.vcxproj]

I was a bit puzzled at first since it was the only error and it took me quite some time before I could identify that the problem came from offsetof.

The problem come from using the offsetof macro inside a templated function that takes a parameter pack in.

I do not think this code is doing anything illegal or is using undefined behavior. So, is the problem on my end or is it a bug in the compiler ?

Thanks

У меня странная ошибка, когда я компилирую свой проект в MSVC.

Я использую Microsoft Visual Studio 15 2017 и компилирую в c ++ 17 (версия MSVC 15.6.85.37198)

Код компилируется на Clang и G ++, но на MSVC выдает ошибку.

Мне удалось уменьшить код, вызывающий ошибку, до следующего фрагмента:

#include <cstddef>

struct Point {
double x;
double y;
double z;
};

template<class... Ps>
void doSomething() {
offsetof(Point, x);
}

int main() {
doSomething();
}

Это дает мне следующую ошибку:

main.cpp(10): fatal error C1903: unable to recover from previous error(s); stopping compilation [buildexample.vcxproj]

Сначала я был немного озадачен, так как это была единственная ошибка, и мне потребовалось довольно много времени, чтобы понять, что проблема возникла из-за offsetof.

Проблема исходит от использования offsetof макрос внутри шаблонной функции, которая принимает пакет параметров.

Я не думаю, что этот код делает что-то незаконное или использует неопределенное поведение. Итак, проблема с моей стороны или это ошибка в компиляторе?

Спасибо

2

Решение

поскольку Point это стандартный тип макета, использование offsetof(Point, x) четко определен.

Тот факт, что MSVC17 не может скомпилировать ваш минимальный пример, безусловно, является ошибкой из-за его неспособности полностью поддерживать пакеты параметров шаблона.

4

Другие решения

Других решений пока нет …

I’m writing Monopoly game with C++ and SFML. My application already has around 20 classes and they work together pretty well but I can’t find solution for one problem. First I need to show you a bit of my code, I’m sorry if I post too much code (Ill try to paste simple minimum), but problems happen all accross my application once I add 1 line of code — #include "GameEngine.h" into Field.h and I dont really know what. Let’s start with heart of application, GameState class that has GameLoop inside

class GameState : public State {        
    sf::Clock m_clock;
    sf::Sprite m_background;    
    GameEngine m_gameEngine;    
public:
    GameState();

    void initialise();
    void handleUserInput();
    void update(sf::Time);
    void draw();
};

GameState::GameState(std::shared_ptr<ApplicationData> data) : m_gameEngine(2, "John", "Richard") {
//2 players named John and Richard, just for tests now
}

Then class that handles all the logic, GameEngine

    class GameEngine {
        //players
        std::vector<Player> m_players;
        int m_numberOfPlayers;
        int m_activePlayer = 0;

        //game objects
        GameBoard m_gameBoard;
 public:
        GameEngine(int, std::string, std::string);  
        GameBoard& getBoard() { return m_gameBoard; }   
        Player& getActivePlayer() { return m_players[m_activePlayer]; }
    }; 

For now, it just creates two players

GameEngine::GameEngine(int numberOfPlayers, std::string playerOneName, std::string playerTwoName) 
    : m_numberOfPlayers(numberOfPlayers), m_firstDice(FIRST_DICE_POSITION_X, FIRST_DICE_POSITION_Y), 
      m_secondDice(SECOND_DICE_POSITION_X, SECOND_DICE_POSITION_Y) {    
    m_players.push_back(Player(playerOneName, sf::Color::Red, -5, 0));
    m_players.push_back(Player(playerTwoName, sf::Color::Blue, -5, 0)); 
}

Player class is nothing special, few variables and getter and setter functions

class Player {  
    int m_positionID = 0;
    std::string m_name;
    sf::CircleShape m_token;
};

Another significant part is GameBoard

class GameBoard {   
        std::array<std::shared_ptr<Field>, BOARD_SIZE> m_board; 
    public:
        GameBoard();
        ~GameBoard() = default;
        std::shared_ptr<Field>& getField(size_t index) { return m_board[index]; }   
    };

And finnaly Field where all the problems start

class Field {
protected:          
    int m_positionID;
    float m_positionX;
    float m_positionY;    
    bool m_buyable;
public:
    Field() {}
    Field::Field(int positionId, float positionX, float positionY, bool buyable) :
        m_positionID(positionId), m_positionX(positionX), m_positionY(positionY), m_buyable(buyable) { }
    virtual ~Field() = default;
    virtual void calculateCharge(GameEngine&) = 0;
};

Field is base class for all my fields in game like Property, Start, GoToJail, etc. I want something like that: player rolls the dice, he is moved to new position, this position is checked (inside GameEngine)

m_board.getField(m_gameEngine.getActivePlayer().getPositionID())->calculateCharge();

Now calculateCharge() will perform a bit different action for every class, simple runtime polymorphism, but I want this function to actually call some functions from inside GameEngine, thats why I want to pass GameEngine& into this function, but once I ‘#include GameEngine.h’ into ‘Field.h’, I got

error C2504: ‘Field’: base class undefined

followed by several errors from derived classes, that they cannot access members (which are protected), etc, whole inheritance isnt working anymore, and after few errors I got

fatal error C1903: unable to recover from previous error(s); stopping
compilation

I tried to add forward declaration but it doesnt help. I dont really know how to fix this.

Message Text

unable to recover from previous error(s); stopping compilation

Circumstances

The compiler typically attempts some sort of continuation after an error, and
it is not the policy of these notes ever to criticise (or even bring to attention)
any quirks in the compiler’s sometimes valiant attempts at such continuation. In
some cases, the compiler declines to try continuing, even though the error would
ideally not be fatal. The visible result is fatal error C1903. It may be that something
unusual is noticed about the circumstances, such that the error is ordinarily not
fatal but in these circumstances is too difficult and is instead declared fatal.
It may just be that the error is always fatal in practice because although the compiler’s
writers have not defined a fatal error number for it, and might not want to, neither
have they yet got round to writing code for any continuation.

One error for which the front-end C++ compiler presently provides no continuation
in any circumstances is C2687. To generate this error, ignore everything that the
product documentation says about it, and instead attempt an out-of-line definition
of a class that is nested in a template class, e.g.,

template <typename T> class Test
{
    class Nested;
};

template <typename T> class Test <int> :: Nested        // C2687 and C1903
{
};

One case is known where fatal error C1903 is the one and only message given to
the user, who may then puzzle over the “previous error(s)” that are never described.
To observe, compile the one-line source file:

#import <rubbish> ptrsize (0)

CPU Exceptions

Fatal error C1903 can also occur in response to a CPU exception. If there has
already been an error during compilation, no matter how long before and how well
recovered, then a CPU exception that would ordinarily be reported as an internal
compiler error C1001, specifically in the case that version
13.00.9466 attributes to

compiler file 'msc1.cpp', line 2844

is instead reported as fatal error C1903. The thinking is presumably that the
compiler is continuing from an error and the CPU exception is an artifact of the
continuation having been too bold. Though the exception is more or less by definition
a coding error in the compiler, it may reasonably be forgiven and should be regarded
as an internal compiler error only if it persists after the other errors have been
fixed.

For example, compile the following with the /Zc:wchar_t
option and without /Yu.

1;                              // C2059
#if _WCHAR_T_DEFINED            // C1903
#endif

The second line (indeed, any evaluation of the built-in macro

_WCHAR_T_DEFINED
)
is known to trigger a coding error in the compiler. The first line is added just
to contrive a previous error. Delete the first line, i.e., deal with the contrived
error, to reveal that the C1903 is really a C1001.

  • Far cry 5 ошибка snowshoe 9e42873b как исправить
  • Far cry 5 ошибка snowshoe 64eeaa8d
  • Far cry 5 ошибка snowshoe 593036c0 ps4
  • Far cry 5 ошибка snowshoe 2096ea55 как исправить ошибку
  • Far cry 5 ошибка bookworm 6e739f5b