[llvm-bugs] [Bug 36132] New: Nested Template Visibility is Not Right
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Jan 28 23:24:59 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=36132
Bug ID: 36132
Summary: Nested Template Visibility is Not Right
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: bluechristlove at 163.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Code:
#define HIDDEN __attribute__((visibility("hidden")))
#define PROTECTED __attribute__((visibility("protected")))
#define DEFAULT __attribute__((visibility("default")))
template <typename T> class HIDDEN C {
public:
template <typename U> class PROTECTED D {
public:
void f();
};
};
int main() {
C<int>::D<int> d;
d.f();
}
When we compile it and dump the symbol proporty:
Symbol table '.symtab' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS c.C
2: 0000000000000000 0 SECTION LOCAL DEFAULT 2
3: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND .TOC.
4: 0000000000000000 0 NOTYPE GLOBAL HIDDEN UND C<int>::D<int>::f()
5: 0000000000000000 76 FUNC GLOBAL DEFAULT [<localentry>: 8] 2
main
We can see that function's visibility is HIDDEN. But it should belongs to D's
visibility: PROTECTED.
When we use GCC:
Symbol table '.symtab' contains 12 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS c.C
2: 0000000000000000 0 SECTION LOCAL DEFAULT 1
3: 0000000000000000 0 SECTION LOCAL DEFAULT 3
4: 0000000000000000 0 SECTION LOCAL DEFAULT 4
5: 0000000000000000 0 SECTION LOCAL DEFAULT 5
6: 0000000000000000 0 SECTION LOCAL DEFAULT 7
7: 0000000000000000 0 SECTION LOCAL DEFAULT 8
8: 0000000000000000 0 SECTION LOCAL DEFAULT 6
9: 0000000000000000 84 FUNC GLOBAL DEFAULT [<localentry>: 8] 1
main
10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND .TOC.
11: 0000000000000000 0 NOTYPE GLOBAL PROTECTED UND
C<int>::D<int>::f()
We can see that GCC's behaviour is right.
Additionally, if we don't use nested template, i.e.
#define HIDDEN __attribute__((visibility("hidden")))
#define PROTECTED __attribute__((visibility("protected")))
#define DEFAULT __attribute__((visibility("default")))
template<typename T>
class HIDDEN C {
public:
class PROTECTED D {
public:
void f();
};
};
int main() {
C<int>::D d;
d.f();
}
Clang can get the right visibility.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180129/545c0efd/attachment.html>
More information about the llvm-bugs
mailing list