Bug 90942 - Attributes might be implicitly set to a type can't be overridden
Summary: Attributes might be implicitly set to a type can't be overridden
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL: https://gcc.gnu.org/bugzilla/show_bug...
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-19 16:03 UTC by Marco Trevisan
Modified: 2019-06-25 10:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Trevisan 2019-06-19 16:03:40 UTC
Use something like this:

// Test case, wrongexport.cpp
// g++ -shared -fPIC -o /tmp/libwrong.so wrongexport.cpp -fvisibility=hidden
// nm -DC /tmp/libwrong.so | grep Astruct # misses AStruct<int> in gcc!!!

#define EXPORT __attribute__ ((visibility ("default")))

template <typename T>
struct AStruct {
    AStruct(T) {}
};

template struct EXPORT AStruct<bool>;

void ImplicitSpecializationDefinition(AStruct<int>) {}

// Ignored in g++, clang++ will export it
template struct EXPORT AStruct<int>;

---

When compiled with clang++:
 - No error
 - Exported symbols are (as expected):
0000000000001110 W AStruct<bool>::AStruct(bool)
0000000000001110 W AStruct<bool>::AStruct(bool)
0000000000001130 W AStruct<int>::AStruct(int)
0000000000001130 W AStruct<int>::AStruct(int)


When compiled with g++:
 - Warns:
 /tmp/wrongexport.cpp:17:24: warning: type attributes ignored after type is already defined [-Wattributes]
 template struct EXPORT AStruct<int>;
                        ^~~~~~~~~~~~
 - Exported symbols are:
000000000000059c W AStruct<bool>::AStruct(bool)
000000000000059c W AStruct<bool>::AStruct(bool)

So, it's missing the symbols for AStruct<int>::AStruct(int) because the fact that is used as parameter, cause an implicit definition with default attributes.

I think that in such case g++ should instead allow to define attributes at later point when those are not explicitly set.

This affects mozjs https://bugzilla.mozilla.org/show_bug.cgi?id=1560064