[clang] [Clang] Fix some assertions not looking through type sugar (PR #92299)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 17 06:21:16 PDT 2024
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/92299
>From b6cb1c53a20637255bf869617b60155bfb636c60 Mon Sep 17 00:00:00 2001
From: Mital Ashok <mital at mitalashok.co.uk>
Date: Wed, 15 May 2024 18:50:14 +0100
Subject: [PATCH] [Clang] Fix some assertions not looking through type sugar
Fixes #92284
---
clang/lib/AST/ExprConstant.cpp | 2 +-
clang/lib/Sema/SemaInit.cpp | 2 +-
clang/test/SemaCXX/paren-list-agg-init.cpp | 16 ++++++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..dca2b5d016738 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11420,7 +11420,7 @@ bool ArrayExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E,
bool ArrayExprEvaluator::VisitCXXParenListInitExpr(
const CXXParenListInitExpr *E) {
- assert(dyn_cast<ConstantArrayType>(E->getType()) &&
+ assert(E->getType()->isConstantArrayType() &&
"Expression result is not a constant array type");
return VisitCXXParenListOrInitListExpr(E, E->getInitExprs(),
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 708286e192f9c..77d0075fbfd88 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5511,7 +5511,7 @@ static void TryOrBuildParenListInitialization(
<< SE->getSourceRange();
return;
} else {
- assert(isa<IncompleteArrayType>(Entity.getType()));
+ assert(Entity.getType()->isIncompleteArrayType());
ArrayLength = Args.size();
}
EntityIndexToProcess = ArrayLength;
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c1964a5a9eb00..e8a9cd7e0509c 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -313,3 +313,19 @@ namespace GH63903 {
constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 'const S' from a parenthesized list of values is a C++20 extension}} \
// expected-error {{constexpr variable 's' must be initialized by a constant expression}}
}
+
+namespace GH92284 {
+ using T = int[1]; T x(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'T' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}}
+ using Ta = int[2]; Ta a(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'Ta' (aka 'int[2]') from a parenthesized list of values is a C++20 extension}}
+ using Tb = int[2]; Tb b(42,43);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'Tb' (aka 'int[2]') from a parenthesized list of values is a C++20 extension}}
+ using Tc = int[]; Tc c(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+ using Td = int[]; Td d(42,43);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
+ template<typename T, int Sz> using ThroughAlias = T[Sz];
+ ThroughAlias<int, 1> e(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'ThroughAlias<int, 1>' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}}
+}
More information about the cfe-commits
mailing list