[PATCH] D79548: Fix false positive with warning -Wnon-c-typedef-for-linkage

2020-05-07 Thread Richard Trieu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ae537c2220f: Fix false positive with 
-Wnon-c-typedef-for-linkage (authored by rtrieu).

Changed prior to commit:
  https://reviews.llvm.org/D79548?vs=262536=262808#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79548/new/

https://reviews.llvm.org/D79548

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


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -133,3 +133,23 @@
 int arr[ ? 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
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4425,8 +4425,11 @@
 isa(D))
   continue;
 auto *MemberRD = dyn_cast(D);
-if (!MemberRD)
+if (!MemberRD) {
+  if (D->isImplicit())
+continue;
   return {NonCLikeKind::OtherMember, D->getSourceRange()};
+}
 
 //  -- contain a lambda-expression,
 if (MemberRD->isLambda())


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -133,3 +133,23 @@
 int arr[ ? 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
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4425,8 +4425,11 @@
 isa(D))
   continue;
 auto *MemberRD = dyn_cast(D);
-if (!MemberRD)
+if (!MemberRD) {
+  if (D->isImplicit())
+continue;
   return {NonCLikeKind::OtherMember, D->getSourceRange()};
+}
 
 //  -- contain a lambda-expression,
 if (MemberRD->isLambda())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79548: Fix false positive with warning -Wnon-c-typedef-for-linkage

2020-05-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79548/new/

https://reviews.llvm.org/D79548



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79548: Fix false positive with warning -Wnon-c-typedef-for-linkage

2020-05-06 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu created this revision.
rtrieu added a reviewer: rsmith.
Herald added a project: clang.

Fix false positives for -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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79548

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


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -133,3 +133,20 @@
 int arr[ ? 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;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4425,8 +4425,11 @@
 isa(D))
   continue;
 auto *MemberRD = dyn_cast(D);
-if (!MemberRD)
+if (!MemberRD) {
+  if (D->isImplicit())
+continue;
   return {NonCLikeKind::OtherMember, D->getSourceRange()};
+}
 
 //  -- contain a lambda-expression,
 if (MemberRD->isLambda())


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -133,3 +133,20 @@
 int arr[ ? 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;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4425,8 +4425,11 @@
 isa(D))
   continue;
 auto *MemberRD = dyn_cast(D);
-if (!MemberRD)
+if (!MemberRD) {
+  if (D->isImplicit())
+continue;
   return {NonCLikeKind::OtherMember, D->getSourceRange()};
+}
 
 //  -- contain a lambda-expression,
 if (MemberRD->isLambda())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits