diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-04-24 00:08:02 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-04-24 00:08:02 +0000 |
| commit | 3ac3e9ce047450d4fa9489055ca243bcfc035bd0 (patch) | |
| tree | 365164f11caa5d079bc3e0757792a1df55286cc0 /clang/lib | |
| parent | 7fee2b89fd6e5101bc590e0741f4d7a82b7715e1 (diff) | |
| download | bcm5719-llvm-3ac3e9ce047450d4fa9489055ca243bcfc035bd0.tar.gz bcm5719-llvm-3ac3e9ce047450d4fa9489055ca243bcfc035bd0.zip | |
Add missing diagnostic for anonymous struct/union definitions that don't
introduce any names.
llvm-svn: 359051
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b6ddd860399..1d0881856e3 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4817,6 +4817,18 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, Invalid = true; } + // C++ [dcl.dcl]p3: + // [If there are no declarators], and except for the declaration of an + // unnamed bit-field, the decl-specifier-seq shall introduce one or more + // names into the program + // C++ [class.mem]p2: + // each such member-declaration shall either declare at least one member + // name of the class or declare at least one unnamed bit-field + // + // For C this is an error even for a named struct, and is diagnosed elsewhere. + if (getLangOpts().CPlusPlus && Record->field_empty()) + Diag(DS.getBeginLoc(), diag::ext_no_declarators) << DS.getSourceRange(); + // Mock up a declarator. Declarator Dc(DS, DeclaratorContext::MemberContext); TypeSourceInfo *TInfo = GetTypeForDeclarator(Dc, S); |

