Author Topic: preprocessor expansion not working correctly  (Read 7417 times)

Offline Curmudgeon

  • Single posting newcomer
  • *
  • Posts: 6
preprocessor expansion not working correctly
« on: June 04, 2009, 04:35:11 pm »
I'm not sure where this post belongs, but this seems like the right place.

background:
I'm an experienced programmer but new to code::blocks

Problem:
GoogleTest ( gtest-1.3.0.zip ) does not compile under code blocks but does under msvc.
I imported the project from the provided msvc sln file.
It did not correctly import the include directories for the project(s).
I set them manually.

When I try to compile I get:

Code
-------------- Build: Debug Win32 in gtest_unittest ---------------

cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release
cl : Command line warning D9002 : ignoring unknown option '/MLd'
gtest_unittest.cc
c:\program files\microsoft visual studio 9.0\vc\include\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
c:\temp\gtest-1.3.0\test\gtest_unittest.cc(913) : error C2065: '__LINE__Var' : undeclared identifier
c:\temp\gtest-1.3.0\test\gtest_unittest.cc(925) : error C2065: '__LINE__Var' : undeclared identifier

Searching for '__LINE__Var' yields no matches.

This is the first failure line:

Code
EXPECT_FATAL_FAILURE(ASSERT_TRUE(false), "");

If you find the definition of EXPECT_FATAL_FAILURE and substitute in the parameters it compiles fine:

Code
 do {
    class GTestExpectFatalFailureHelper {
     public:
      static void Execute() { ASSERT_TRUE(false); }
    };
    ::testing::TestPartResultArray gtest_failures;
    ::testing::internal::SingleFailureChecker gtest_checker(
        &gtest_failures, ::testing::TPRT_FATAL_FAILURE, (""));
    {
      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(
          ::testing::ScopedFakeTestPartResultReporter::
          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);
      GTestExpectFatalFailureHelper::Execute();
    }
  } while (false);

Any suggestions?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: preprocessor expansion not working correctly
« Reply #1 on: June 04, 2009, 04:52:59 pm »
I imported the project from the provided msvc sln file.
You cannot expect this to work without any modifications. It also depends on the MSVC version you are using. The importer is based on VS2003 (IIRC) and had been adopted slightly to match newer versions, too. Hence the compiler options changed faily well up to MSVC2008 that we would really need several importers for each MSVC version.

But based on my daily work I can tell that I managed to port *every* MSVC project (V6-2008) to C::B but with more or less modifications. Especially e.g. the manifest handling is not truly supported and needs to be hand-crafted afterwards.

It did not correctly import the include directories for the project(s).
Well - that really should work. I wonder why it doesn't. Are the directories based on macros or alike? Could you provide the project / solution file(s)?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Curmudgeon

  • Single posting newcomer
  • *
  • Posts: 6
Re: preprocessor expansion not working correctly
« Reply #2 on: June 04, 2009, 05:12:09 pm »

>You cannot expect this to work without any modifications.

This would seem to be an issue with the compiler preprocessor. When I manually do the text substitution it compiles. Any suggestion what IDE setting is missing/wrong?


The project files were unmodified and as provided by the googletest project.

Here's one.

Code
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="gtest_unittest"
ProjectGUID="{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/gtest_unittest.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/gtest_unittest.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/gtest_unittest.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
<ProjectReference
ReferencedProjectIdentifier="{3AF54C8A-10BF-4332-9147-F68ED9862032}"
Name="gtest_main"/>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath="..\test\gtest_unittest.cc">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="1"
AdditionalIncludeDirectories="&quot;..&quot;;&quot;..\include&quot;"
BasicRuntimeChecks="0"
UsePrecompiledHeader="0"
DebugInformationFormat="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;..&quot;;&quot;..\include&quot;"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: preprocessor expansion not working correctly
« Reply #3 on: June 04, 2009, 05:19:21 pm »
This would seem to be an issue with the compiler preprocessor. When I manually do the text substitution it compiles. Any suggestion what IDE setting is missing/wrong?
I don't exactly get what you mean by that. What pre-processor? What do you substitute to make it work?

Code
						AdditionalIncludeDirectories="&quot;..&quot;;&quot;..\include&quot;"
Aaaah - see, something new for me, too. I don't recall if "AdditionalIncludeDirectories" is handled at all (but I guess: yes) but I think this &quot; XML stuff is *not* handled correctly but I need to try... (Probably through TinyXML we get the right content...)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Curmudgeon

  • Single posting newcomer
  • *
  • Posts: 6
Re: preprocessor expansion not working correctly
« Reply #4 on: June 04, 2009, 05:25:48 pm »
> I don't exactly get what you mean by that. What pre-processor? What do you substitute to make it work?

the goolgetest project uses #defined code as 'macros' for including test conditions.
Like this:

Code
#define EXPECT_FATAL_FAILURE(statement, substr) \
  do { \
    class GTestExpectFatalFailureHelper {\
     public:\
      static void Execute() { statement; }\
    };\
    ::testing::TestPartResultArray gtest_failures;\
    ::testing::internal::SingleFailureChecker gtest_checker(\
        &gtest_failures, ::testing::TPRT_FATAL_FAILURE, (substr));\
    {\
      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
          ::testing::ScopedFakeTestPartResultReporter:: \
          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
      GTestExpectFatalFailureHelper::Execute();\
    }\
  } while (false)

If I copy the code from within the #define and substitute in the text from the invocation parameters it compiles.
If I use the #define it fails with an error that makes no sense to me.

This does not compile:
Code
EXPECT_FATAL_FAILURE(ASSERT_TRUE(false), "");

This (which should be what the compiler expands it to) does compile:

Code
  do {
    class GTestExpectFatalFailureHelper {
     public:
      static void Execute() { ASSERT_TRUE(false); }
    };
    ::testing::TestPartResultArray gtest_failures;
    ::testing::internal::SingleFailureChecker gtest_checker(
        &gtest_failures, ::testing::TPRT_FATAL_FAILURE, (""));
    {
      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(
          ::testing::ScopedFakeTestPartResultReporter::
          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);
      GTestExpectFatalFailureHelper::Execute();
    }
  } while (false);


Offline Curmudgeon

  • Single posting newcomer
  • *
  • Posts: 6
Re: preprocessor expansion not working correctly
« Reply #5 on: June 04, 2009, 05:31:26 pm »
It seems to be a text handling issue in the compiler. Some setting c::b is using that msvc is not is evidently uncovering a bug.