Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/C++/Interaction with the IDE    [ Add a report in this area ]  
Report #:  36326   Status: Closed
Compiler fatal error with Source debugging (-v) option, template and __declspec(package)
Project:  C++Builder Build #:  10.0.2288.42451
Version:    10.0 Submitted By:   Philippe ALLAIN
Report Type:  Basic functionality failure Date Reported:  11/8/2006 2:27:41 AM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   243341
Resolution: Fixed (Resolution Comments) Resolved in Build: : 11.0.2902.10471
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
5.00 out of 5
Total Votes: None
Description
The compiler fatal error occurs when all following conditions are met :
- -v option is active,
- declare a template function or class with __declspec(package) specifier
- write a specialization
- instantiate the specialization.

As I explained in a comment I added to this report, it works fine if any of the conditions above is not met.

By the way, if you do not provide the 'defaut' implementation nor any speciailization, the compiler shouldn't be able to intantiate. It doesn't complain however. This is another bug I reported in report 36329.


It is quite difficult to check against the presence of the -v option in the code because of another bug (see NOTE in code I added in the Comments page) and possibly other conditions not discovered yet.

I haven't found yet the benefit of the -v option but it is probably something you would check one day just because you hope it can help you....

Workaround is to keep all templatized code internal to the library and use another simple class, that will be exportable, to encapsulate the working class.

Because of the confusing Project Option window (the Build Configuration choice is confusing) , you need to be very careful when changing an option from there and want to apply it to your next compilation.
It is hence useful to display in the message window the actual command line created by the IDE to compile a unit (can't find any more however where this option is).
Steps to Reproduce:
<sysop>
bcc32 qc36326.cpp
note no errors
open and build pr36326.bdsproj using the IDE
erorr:
[C++ Fatal Error] qc36326.cpp(22): F1001 Internal code generator error

original steps follow:
</sysop>
1- Copy following text to any project unit

//declaration and (optional for this demo) default implementation
template <class T> void __declspec(package) f1() {};

//specialization:
template<> void f1<int>() {};

//instantiation:
template void f1<int>();

2 - Ensure the -v option is active (Source debugging)
3 - Compile

EXPECTED: compilation without any error

ACTUAL:
[C++ Fatal Error] F1001 Internal code generator error
Workarounds
Avoid the -v option when you want to export a templatized function of class with specialization.
Or
Keep you class internal and use another one to encapsulate it and that you export.
Attachment
qc36326.zip
Comments

Philippe ALLAIN at 11/8/2006 3:48:06 AM -
The initial text I inserted in the Steps page is the following.
I changed it to more concise information as it is meant to be there but I didn't want to throw out the extra information I embedded in this demo.

// Copy this text to a CPP unit and compile.
//
// With option -v (Source debugging) in compiler command line,
// the following code generates :
// [C++ Fatal Error] F1001 Internal code generator error
//
// Error does not occur if you do any one of the following :
// - remove the -v option
// - remove the __declspec(package) specifier from the declaration
// - remove the specialization
// - remove the instanciation

// -v can be avoided but unfortunately only by not specifying it at all:
//#pragma option -v-
//#pragma option -v
// are both unrecognized so that you cannot isolate the code in a file that
// would need special attention regarding this option.

// just to see whether -v is active or not:
// need to check 'Show general messages' option in C++Compiler|Compiling page
// otherwise no message is displayed with pragma message.

#pragma defineonoption OPTIONSEEN -v
#ifdef OPTIONSEEN
#
pragma message "Option -v is ACTIVE"
#
undef OPTIONSEEN
#else
#
pragma message "Option -v is NOT active"
#endif
/// NOTE: I just discovered while preparing this report that the #pragma defineonoption OPTIONSEEN -v
/// does not work if option -vi is set (inlining inline functions). If both options are checked (and actually
/// given to the compiler), you'll get the "Option -v is NOT active" message. Misleading!
/// I'll prepare another report for that.

//declaration and (optional for this demo) default implementation
template <class T> void __declspec(package) f1() {};

//specialization:
template<> void f1<int>() {};

//instantiation:
template void f1<int>();

Roddy Pratt at 11/8/2006 7:05:57 AM -
My head threatens to explode when I look at templates, but I can duplicate the Internal error as described.

Interestingly, I get the error even with -v option disabled...

Philippe ALLAIN at 11/8/2006 8:02:54 AM -
Because of the bug I described in report 36328, the message telling whether -v is enabled or not is valid only when -vi is NOT specified. Another way is to explicitely specify -vi-

I should therefore have added the following line before the #pragma defineonoption... (cf. my first comment):
#pragma option -vi-

Server Response from: ETNACODE01