Index: lib/Sema/SemaDeclAttr.cpp =================================================================== --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -3008,6 +3008,10 @@ static void handleTransparentUnionAttr(Sema &S, Decl *D, const AttributeList &Attr) { + if (S.getLangOpts().CPlusPlus) { + return; + } + // Try to find the underlying union declaration. RecordDecl *RD = nullptr; TypedefNameDecl *TD = dyn_cast(D); Index: test/SemaCXX/attr-gnu.cpp =================================================================== --- test/SemaCXX/attr-gnu.cpp +++ test/SemaCXX/attr-gnu.cpp @@ -27,3 +27,19 @@ void test3() __attribute__((cf_unknown_transfer)) override {} // Ok, not known to GCC. }; } + +template +union Tu { T b; } __attribute__((transparent_union)); + +template +union Tu2 { int x; T b; } __attribute__((transparent_union)); + +union Tu3 { int x; } __attribute((transparent_union)); + +void tuTest1(Tu u); // expected-note {{candidate function not viable: no known conversion from 'int' to 'Tu' 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'}} +}