Author: Kristina Bessonova
Date: 2022-03-21T13:21:25+02:00
New Revision: afbe54f2feb0ed3a4d4c03c6107fcdffd21a8394

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

LOG: [clang] Fix wrong -Wunused-local-typedef warning within a template function

Partially fixes PR24883.

The patch sets Reference bit while instantiating a typedef if it
previously was found referenced.

Reviewed By: thakis

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
    clang/test/Modules/odr_hash.cpp
    clang/test/SemaCXX/warn-unused-local-typedef.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index ec993914595f3..8c7f5a4f19658 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -974,6 +974,7 @@ Decl 
*TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
     SemaRef.inferGslPointerAttribute(Typedef);
 
   Typedef->setAccess(D->getAccess());
+  Typedef->setReferenced(D->isReferenced());
 
   return Typedef;
 }

diff  --git 
a/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp 
b/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
index 35ec1cbfd8f7e..88138bf343da5 100644
--- a/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
+++ b/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -193,7 +193,7 @@ int test(float &&f, short &&s) {
 // CHECK-NEXT: | | |-ParmVarDecl [[ADDR_43:0x[a-z0-9]*]] <col:6, col:12> 
col:12 used __t 'float &'
 // CHECK-NEXT: | | `-CompoundStmt [[ADDR_44:0x[a-z0-9]*]] <col:17, line:14:1>
 // CHECK-NEXT: | |   |-DeclStmt [[ADDR_45:0x[a-z0-9]*]] <line:12:3, col:51>
-// CHECK-NEXT: | |   | `-TypedefDecl [[ADDR_46:0x[a-z0-9]*]] <col:3, col:48> 
col:48 _Up 'typename remove_reference<float &>::type':'float'
+// CHECK-NEXT: | |   | `-TypedefDecl [[ADDR_46:0x[a-z0-9]*]] <col:3, col:48> 
col:48 referenced _Up 'typename remove_reference<float &>::type':'float'
 // CHECK-NEXT: | |   |   `-ElaboratedType [[ADDR_47:0x[a-z0-9]*]] 'typename 
remove_reference<float &>::type' sugar
 // CHECK-NEXT: | |   |     `-TypedefType [[ADDR_48:0x[a-z0-9]*]] 
'remove_reference<float &>::type' sugar
 // CHECK-NEXT: | |   |       |-Typedef [[ADDR_10]] 'type'
@@ -211,7 +211,7 @@ int test(float &&f, short &&s) {
 // CHECK-NEXT: |   |-ParmVarDecl [[ADDR_53:0x[a-z0-9]*]] <col:6, col:12> 
col:12 used __t 'short &'
 // CHECK-NEXT: |   `-CompoundStmt [[ADDR_54:0x[a-z0-9]*]] <col:17, line:14:1>
 // CHECK-NEXT: |     |-DeclStmt [[ADDR_55:0x[a-z0-9]*]] <line:12:3, col:51>
-// CHECK-NEXT: |     | `-TypedefDecl [[ADDR_56:0x[a-z0-9]*]] <col:3, col:48> 
col:48 _Up 'typename remove_reference<short &>::type':'short'
+// CHECK-NEXT: |     | `-TypedefDecl [[ADDR_56:0x[a-z0-9]*]] <col:3, col:48> 
col:48 referenced _Up 'typename remove_reference<short &>::type':'short'
 // CHECK-NEXT: |     |   `-ElaboratedType [[ADDR_57:0x[a-z0-9]*]] 'typename 
remove_reference<short &>::type' sugar
 // CHECK-NEXT: |     |     `-TypedefType [[ADDR_58:0x[a-z0-9]*]] 
'remove_reference<short &>::type' sugar
 // CHECK-NEXT: |     |       |-Typedef [[ADDR_18]] 'type'

diff  --git a/clang/test/Modules/odr_hash.cpp b/clang/test/Modules/odr_hash.cpp
index fe51915074239..81899943bc64c 100644
--- a/clang/test/Modules/odr_hash.cpp
+++ b/clang/test/Modules/odr_hash.cpp
@@ -4372,6 +4372,8 @@ template<typename G>
 G* S<G>::Foo(const G* asdf, int*) {}
 #else
 S<X> s;
+// expected-error@first.h:* {{'ParameterTest::S::Foo' has 
diff erent definitions in 
diff erent modules; definition in module 'FirstModule' first 
diff erence is 1st parameter with name 'aaaa'}}
+// expected-note@second.h:* {{but in 'SecondModule' found 1st parameter with 
name 'asdf'}}
 #endif
 }  // ParameterTest
 

diff  --git a/clang/test/SemaCXX/warn-unused-local-typedef.cpp 
b/clang/test/SemaCXX/warn-unused-local-typedef.cpp
index 554ea37eeb282..e7130a24f2db2 100644
--- a/clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ b/clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -238,5 +238,22 @@ void placement_new_and_delete() {
   a->~A_t2();
 }
 
+namespace TypedefInLocalClassOfAMemberOfTemplateClass {
+template<typename> struct A {
+  void foo() {
+    struct Inner {
+      typedef int Int; // no-diag
+      typedef char Char; // expected-warning {{unused typedef 'Char'}}
+      Int m;
+    } b;
+  }
+};
+
+void foo() {
+  A<int> x;
+  x.foo();
+}
+} // TypedefInLocalClassOfTemplateClassMember
+
 // This should not disable any warnings:
 #pragma clang diagnostic ignored "-Wunused-local-typedef"


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

Reply via email to