Community
Participate
Working Groups
Build Identifier: M20110909-1335 we use ifndef/define block to set default log tag if LOG_TAG is not defined in a source file, but CDT places the first LOG_TAG it comes across in a source file into project scope as if it is defined in the header file. * Common.h */ #ifndef COMMON_H_ #define COMMON_H_ #ifndef TAG #define TAG "DefaultTag" #endif #endif /* COMMON_H_ */ /* Source0.cpp */ #define TAG "Source0" #include "Common.h" void test0() { } /* Source1.cpp */ #include "Common.h" void test1(char const* arg) { } int main(int argc, char** argv) { test1(TAG); return (0); } Reproducible: Always Steps to Reproduce: 1. create a C++ project and add three files Common.h, Source0.cpp, Source1.cpp 2. open Common.h, the ifndef block is gray, and TAG resolves to the symbol in Source0.cpp 3. TAG in Source1.cpp resolves to the symbol in Source0.cpp
The file Common.h has pragma-once semantics. In such files CDT does not support multiple versions of the file. You can change the header to disturb CDTs pragma once detection: /* Common.h */ #define USELESS_DEFINITION // prevents pragma-once detection by CDT #ifndef COMMON_H_ #define COMMON_H_ #ifndef TAG #define TAG "DefaultTag" #endif #endif /* COMMON_H_ */
(In reply to comment #1) I see the point. But is there any way to disable the feature, or should I use a feature request? I'm ok with a little performance penalty, and there are real world examples which this feature breaks. For example, current CDT is not able to resolve NULL in NDK's stddef.h (toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/include/stddef.h) if only stdint.h is used, because it always thinks that __need_size_t, __need_ptrdiff_t, __need_wchar_t are defined.
(In reply to comment #2) > (In reply to comment #1) > I see the point. > But is there any way to disable the feature, or should I use a feature request? > I'm ok with a little performance penalty, and there are real world examples > which this feature breaks. We have tried that (see bug 197989) and found the performance penalty is not little. I don't see a reasonable way of doing that. > For example, current CDT is not able to resolve NULL in NDK's stddef.h > (toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/include/stddef.h) > if only stdint.h is used, because it always thinks that __need_size_t, > __need_ptrdiff_t, __need_wchar_t are defined. 'stddef.h' does not have pragma once semantics and is handled correctly.
It would be nice if there were a non-intrusive way of specifying that a file should not have pragma-once semantics, e.g. setting a flag in the file properties, rather than having to modify the file itself.
(In reply to Nathan Ridge from comment #4) > It would be nice if there were a non-intrusive way of specifying that a file > should not have pragma-once semantics, e.g. setting a flag in the file > properties, rather than having to modify the file itself. Preferences for indexing all variants of all header files, or all variants of specific files, have been added in bug 421289. Since the consensus seems to be that this is as much as we can do to support multiple versions of headers with pragma-once semantics, I think this report can be closed.
*** This bug has been marked as a duplicate of bug 421289 ***