[clang] 4ae537c - Fix false positive with -Wnon-c-typedef-for-linkage

via cfe-commits cfe-commits at lists.llvm.org
Thu May 7 19:49:05 PDT 2020


Author: Weverything
Date: 2020-05-07T19:20:08-07:00
New Revision: 4ae537c2220f5064fdc914348dabe70eb10eef85

URL: https://github.com/llvm/llvm-project/commit/4ae537c2220f5064fdc914348dabe70eb10eef85
DIFF: https://github.com/llvm/llvm-project/commit/4ae537c2220f5064fdc914348dabe70eb10eef85.diff

LOG: Fix false positive with -Wnon-c-typedef-for-linkage

Implicit methods for structs can confuse the warning, so exclude checking
the Decl's that are implicit. Implicit Decl's for lambdas still need to
be checked, so skipping all implicit Decl's won't work.

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaDecl.cpp
    clang/test/SemaCXX/anonymous-struct.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 46e541917510..5d3314b4f244 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4425,8 +4425,11 @@ static NonCLikeKind getNonCLikeKindForAnonymousStruct(const CXXRecordDecl *RD) {
         isa<EnumDecl>(D))
       continue;
     auto *MemberRD = dyn_cast<CXXRecordDecl>(D);
-    if (!MemberRD)
+    if (!MemberRD) {
+      if (D->isImplicit())
+        continue;
       return {NonCLikeKind::OtherMember, D->getSourceRange()};
+    }
 
     //  -- contain a lambda-expression,
     if (MemberRD->isLambda())

diff  --git a/clang/test/SemaCXX/anonymous-struct.cpp b/clang/test/SemaCXX/anonymous-struct.cpp
index 017c867c95db..10f6711dd340 100644
--- a/clang/test/SemaCXX/anonymous-struct.cpp
+++ b/clang/test/SemaCXX/anonymous-struct.cpp
@@ -133,3 +133,23 @@ namespace ValidButUnsupported {
     int arr[&f<X> ? 1 : 2];
   } C; // expected-note {{by this typedef}}
 }
+
+namespace ImplicitDecls {
+struct Destructor {
+  ~Destructor() {}
+};
+typedef struct {
+} Empty;
+
+typedef struct {
+  Destructor x;
+} A;
+
+typedef struct {
+  Empty E;
+} B;
+
+typedef struct {
+  const Empty E;
+} C;
+} // namespace ImplicitDecls


        


More information about the cfe-commits mailing list