Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 360919

Summary: [MSVC] preprocessor symbol __STDC__ always defined
Product: [Tools] CDT Reporter: Missing name <Gert.Grossmann>
Component: cdt-parserAssignee: Marc-André Laperle <malaperle>
Status: RESOLVED FIXED QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, malaperle, yevshif, zeratul976
Version: 8.0   
Target Milestone: 9.10.0   
Hardware: PC   
OS: Windows All   
See Also: https://git.eclipse.org/r/150322
https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=4e16631f30de08444342b0ad6622cfcf3cd39fd4
Whiteboard:

Description Missing name CLA 2011-10-14 02:47:18 EDT
Build Identifier: 20110916-0149

Using Visual C++ Tool Chain

Preprocessor symbol __STDC__ always defined although /Za is not given

__STDC__ is only defined in MS VC if compiler switch /Za is given and it isn't a C++ file.

Reproducible: Always

Steps to Reproduce:
1. Create a C or C++ project using Visual C++ Tool Chain, don't set compiler switch /Za
2. Create a new file with following content:

//#undef __STDC__
#ifdef !__STDC__
#define TEST "TEST"         <-- this code is shown as inactive
#endif

3. uncomment "#undef __STDC__" makes TEST macro available
Comment 1 Andrew Gvozdev CLA 2011-10-14 09:52:41 EDT
Currently it is defined by cdt parser in CPreprocessor. But it should be probably defined by scanner discovery where it could inspect toolchain options. If so I think we should remove the macro definition from CPreprocessor class.
Comment 2 Markus Schorn CLA 2011-11-02 06:21:12 EDT
I don't mind removing the builtin definition in the preprocessor. However, we may make the situation worse for other users that then miss the definition for __STDC__.
I think we first need to provide the support for scanner configuration for the microsoft compiler (or do we already have that?) and only afterwards remove the predefined value for __STDC__.
Comment 4 Nathan Ridge CLA 2013-12-15 15:10:09 EST
(In reply to Nathan Ridge from comment #3)
> Fixed in commit
> http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/
> ?id=48d5341bf7fdfd5b11540e032ed2dc969e8c32d1.

Please ignore that, I meant to post that to a different bug.
Comment 5 Eclipse Genie CLA 2019-09-28 23:17:57 EDT
New Gerrit change created: https://git.eclipse.org/r/150322
Comment 7 Marc-André Laperle CLA 2019-10-03 23:46:00 EDT
(In reply to Markus Schorn from comment #2)
> I don't mind removing the builtin definition in the preprocessor. However,
> we may make the situation worse for other users that then miss the
> definition for __STDC__.
> I think we first need to provide the support for scanner configuration for
> the microsoft compiler (or do we already have that?) and only afterwards
> remove the predefined value for __STDC__.

We don't have a scanner configuration for MSVC yet but instead use the CompilerType in GPP/GCC Scanner configuration to decide whether or not to add __STDC__. We also use CompilerType so set other MSVC specific keywords so it is trivial to add another macro. Other scanner configurations not extending GPP/GCCScannerExtensionConfiguration are changed to add __STDC__ for minimizing client impact. Having MSVC have its own scanner configuration and language will be a better solution but can be done separately.
If anyone knows how to do that based on toolchain that would be helpful!

We are also missing the case where files are compiled as C and /Za is used, but that should be much less common. See bug 551758.