Skip to content

Commit

Permalink
[Sema] Handle transparent_union attributes in C mode only
Browse files Browse the repository at this point in the history
This commit marks the transparent_union attributes as C only because clang
doesn't support them in C++ mode. Prior to this commit, clang still tried to
verify these attributes in C++, leading to crashes when analyzing templated
transparent_union unions that have dependent field types. This commit ensures
that such crashes won't happen again.

As a result of this commit clang now displays a warning every time it encounters
a transparent_union attribute in C++ mode.

Differential Revision: https://reviews.llvm.org/D25308


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283995 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
hyp committed Oct 12, 2016
1 parent 419410f commit 38df4e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,7 @@ def TransparentUnion : InheritableAttr {
let Spellings = [GCC<"transparent_union">];
// let Subjects = SubjectList<[Record, TypedefName]>;
let Documentation = [Undocumented];
let LangOpts = [COnly];
}

def Unavailable : InheritableAttr {
Expand Down
16 changes: 16 additions & 0 deletions test/SemaCXX/attr-gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@ class D : public B {
void test3() __attribute__((cf_unknown_transfer)) override {} // Ok, not known to GCC.
};
}

template<typename T>
union Tu { T b; } __attribute__((transparent_union)); // expected-warning {{'transparent_union' attribute ignored}}

template<typename T>
union Tu2 { int x; T b; } __attribute__((transparent_union)); // expected-warning {{'transparent_union' attribute ignored}}

union Tu3 { int x; } __attribute((transparent_union)); // expected-warning {{'transparent_union' attribute ignored}}

void tuTest1(Tu<int> u); // expected-note {{candidate function not viable: no known conversion from 'int' to 'Tu<int>' for 1st argument}}
void tuTest2(Tu3 u); // expected-note {{candidate function not viable: no known conversion from 'int' to 'Tu3' for 1st argument}}
void tu() {
int x = 2;
tuTest1(x); // expected-error {{no matching function for call to 'tuTest1'}}
tuTest2(x); // expected-error {{no matching function for call to 'tuTest2'}}
}

0 comments on commit 38df4e8

Please sign in to comment.