[clang] 073c199 - [Clang][AST] Don't use canonical type when checking dependence in Type::isOverloadable (#98563)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 24 09:02:50 PDT 2024


Author: Krystian Stasiowski
Date: 2024-07-24T12:02:45-04:00
New Revision: 073c199ae79f4bf9a89fcbf103cbdd6333c8512b

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

LOG: [Clang][AST] Don't use canonical type when checking dependence in Type::isOverloadable (#98563)

Fixes #97646.

Added: 
    clang/test/SemaCXX/typeof.cpp

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/include/clang/AST/Type.h
    clang/test/SemaCXX/decltype.cpp

Removed: 
    clang/test/SemaCXX/typeof_unqual.cpp


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c80c2ebbac9a7..65de90f69e198 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -147,6 +147,8 @@ Bug Fixes to Attribute Support
 Bug Fixes to C++ Support
 ^^^^^^^^^^^^^^^^^^^^^^^^
 
+- Fixed a crash when an expression with a dependent ``__typeof__`` type is used as the operand of a unary operator. (#GH97646)
+
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
 

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 25defea58c2dc..72723c7c56e07 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8434,7 +8434,7 @@ inline bool Type::isUndeducedType() const {
 /// Determines whether this is a type for which one can define
 /// an overloaded operator.
 inline bool Type::isOverloadableType() const {
-  if (!CanonicalType->isDependentType())
+  if (!isDependentType())
     return isRecordType() || isEnumeralType();
   return !isArrayType() && !isFunctionType() && !isAnyPointerType() &&
          !isMemberPointerType();

diff  --git a/clang/test/SemaCXX/decltype.cpp b/clang/test/SemaCXX/decltype.cpp
index 96abb60836e40..9961c5e2bd918 100644
--- a/clang/test/SemaCXX/decltype.cpp
+++ b/clang/test/SemaCXX/decltype.cpp
@@ -139,6 +139,14 @@ namespace GH58674 {
   }
 }
 
+namespace GH97646 {
+  template<bool B>
+  void f() {
+    decltype(B) x = false;
+    !x;
+  }
+}
+
 template<typename>
 class conditional {
 };

diff  --git a/clang/test/SemaCXX/typeof_unqual.cpp b/clang/test/SemaCXX/typeof.cpp
similarity index 68%
rename from clang/test/SemaCXX/typeof_unqual.cpp
rename to clang/test/SemaCXX/typeof.cpp
index 335e57995377c..421cfc59f5311 100644
--- a/clang/test/SemaCXX/typeof_unqual.cpp
+++ b/clang/test/SemaCXX/typeof.cpp
@@ -3,3 +3,11 @@
 typeof_unqual(int) u = 12; // expected-error {{expected function body after function declarator}}
 __typeof_unqual(int) _u = 12;
 __typeof_unqual__(int) __u = 12;
+
+namespace GH97646 {
+  template<bool B>
+  void f() {
+    __typeof__(B) x = false;
+    !x;
+  }
+}


        


More information about the cfe-commits mailing list