Internal compiler error in condition with bool property

1.1k Views Asked by At

lately I have been faced with a strange problem that a simple source did not want to compile. I was looking for solutions (and cause) in many sites but without good effects (except bugs reports but I have not found there direct cause ).

Below I present simple code to reproduce that situation:

struct Foo {
  Foo() : m_x( true ) {}
  __property bool x = { read=m_x };

  private:
    bool m_x;
};

template<typename T>
struct TMyPointer {
  T * m_ptr;
  TMyPointer( T * ptr ) : m_ptr( ptr ) {}
  ~TMyPointer()
  {
    delete m_ptr;
  }

  T * operator->() const
  {
    return Get();
  }

  T * Get() const
  {
    if( m_ptr == NULL )
      ; // some error handling

    return m_ptr;
  }
};

int _tmain(int argc, _TCHAR* argv[])
{
  TMyPointer<Foo> bar( new Foo );

  if( bar->x && 1 == 1 ) ; // Failed
  if( 1 == 1 && bar->x ) ; // OK
  if( !!bar->x && 1 == 1 ) ; // OK
  if( bar->x == true && 1 == 1 ) ; // OK
  if( (bar->x) && 1 == 1 ) ; // OK

  return 0;
}

Compiler has failed to compile first condition inside main function. What stranger compilation of other equivalent conditions is finished successfully.

That's behavior I have only during release compilation. To reproduce I have used Embarcadero® C++Builder® XE5 Version 19.0.13476.4176

Error message: [bcc32 Fatal Error] File1.cpp(43): F1004 Internal compiler error at 0x14470090 with base 0x14410000

Anybody knows what is the problematic in above example? Maybe usage templates with properties mechanism is the cause?

3

There are 3 best solutions below

1
moses.nebogipfel On

In my case is simple solution it seems to be problematic condition inside Get method. When I change

if( m_ptr == NULL )

to equivalent form

if( !m_ptr )

everything compile without errors.

I am writing about it here becouse I would like to share my insights - it can be helpfully for somebody.

0
Spektre On

recently I got similar ICE (once my source code grows in size) and your solution seemingly helped for a while but not really as after some minor changes in code ICE resurfaced again. Based on the behavior of mine problem:

  • IDE: BDS2006 Turbo C++ explorer (its version of BCB between BCB6 and RAD)
  • Huge win32 project (several MBytes of code involving USB,OpenGL,CAD/CAM)
  • Each part of code is tested for years and compilable separably problem occurs once they together and code grows too big
  • Project compiles fine at first run but after that any recompile fails

The temporary workaround was to close IDE, delete all obj,tds,exe,... files restart IDE and compile again.

I assumed compiler and or IDE leaks or overwrites some parts of itself corrupting its functionality. As the problem persist after IDE restart without deleting temp files I assumed it has something to do with debug info stored in them.

So I played with Project->Options->Debugging settings and turning off this:

  • Inline function expansion (-vi)

Helped (not even IDE restart or temp file removal was needed).

0
Windwaker On

Don't have enough reputation to upvote or comment someone else's posts, but I have recently found the same solution as in @Spektre reply.

Disabling Inline function expansion fixed our multiple-year problems with completely unrelated internal compiler errors on random projects. We only experienced them on MSBUILD scripts in Release config.

I found this out by going over all the compiler options in Release config that were different from Debug config and changed them one-by-one to match Debug config through msbuild parameters for the entire solution/projectgroup. And eventually it started to build without any errors when I've disabled Inline function expansion option.

  • These problems happened and I confirmed the fix on C++ Builder XE5;
  • This kept on resurfacing at random for as long as I can remember (Borland C++ 2006 and later)
  • The older developers used to try and revert latest commits until it started compiling again... Which is a pain in the behind.

Anyone looking for solution to pass a parameter to an MSBUILD command (for all targets in the script) add this line to the msbuild.exe call:

msbuild.exe Targets.xml /p:BCC_InlineFunctionExpansion=false /t:Build