Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363117 - No support for multiple versions of header with pragma once semantics
Summary: No support for multiple versions of header with pragma once semantics
Status: CLOSED DUPLICATE of bug 421289
Alias: None
Product: CDT
Classification: Tools
Component: cdt-indexer (show other bugs)
Version: 8.1.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-07 21:09 EST by Yu Xiaolei CLA
Modified: 2014-04-28 15:12 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yu Xiaolei CLA 2011-11-07 21:09:45 EST
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
Comment 1 Markus Schorn CLA 2011-11-08 05:31:47 EST
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_ */
Comment 2 Yu Xiaolei CLA 2011-11-21 23:58:55 EST
(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.
Comment 3 Markus Schorn CLA 2011-11-22 02:55:36 EST
(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.
Comment 4 Nathan Ridge CLA 2012-01-12 22:34:37 EST
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.
Comment 5 Nathan Ridge CLA 2014-04-28 13:11:14 EDT
(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.
Comment 6 Marc-André Laperle CLA 2014-04-28 15:12:48 EDT

*** This bug has been marked as a duplicate of bug 421289 ***