[clang] [Clang][Sema] Fix crash when diagnosing near-match for 'constexpr' redeclaration in C++11 (PR #92452)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri May 17 05:01:14 PDT 2024


================
@@ -1527,20 +1527,20 @@ struct DeclaratorChunk {
 
     /// Retrieve the location of the 'const' qualifier.
     SourceLocation getConstQualifierLoc() const {
-      assert(MethodQualifiers);
-      return MethodQualifiers->getConstSpecLoc();
+      return MethodQualifiers ? MethodQualifiers->getConstSpecLoc()
----------------
AaronBallman wrote:

`DeclSpec.h` is basically used only to gather information from the parser, and so from that perspective, I think the `assert` makes sense. If the caller is asking for the location of the `const` qualifier and one wasn't written in source, the caller is doing something out of the ordinary.

I think the fix-it code should be guarded by a call to `hasMethodTypeQualifiers()` instead.

https://github.com/llvm/llvm-project/pull/92452


More information about the cfe-commits mailing list