Skip to content

Commit

Permalink
[Clang] Fix some assertions not looking through type sugar (#92299)
Browse files Browse the repository at this point in the history
Fixes #92284

Co-authored-by: cor3ntin <[email protected]>
  • Loading branch information
MitalAshok and cor3ntin authored Jul 17, 2024
1 parent c5c1bd1 commit 554febd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11478,7 +11478,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(),
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5621,7 +5621,7 @@ static void TryOrBuildParenListInitialization(
<< SE->getSourceRange();
return;
} else {
assert(isa<IncompleteArrayType>(Entity.getType()));
assert(Entity.getType()->isIncompleteArrayType());
ArrayLength = Args.size();
}
EntityIndexToProcess = ArrayLength;
Expand Down
21 changes: 20 additions & 1 deletion clang/test/SemaCXX/paren-list-agg-init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ namespace GH63903 {
// expected-error {{constexpr variable 's' must be initialized by a constant expression}}
}


namespace gh62863 {

int (&&arr)[] = static_cast<int[]>(42);
// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
int (&&arr1)[1] = static_cast<int[]>(42);
Expand All @@ -333,4 +333,23 @@ int (&&arr6)[2] = (int[])(42); // expected-error {{reference to type 'int[2]' co
// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
int (&&arr7)[3] = (int[3])(42);
// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}

}

namespace GH92284 {

using T = int[1]; T x(42);
// beforecxx20-warning@-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@-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@-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@-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@-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@-1 {{aggregate initialization of type 'ThroughAlias<int, 1>' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}}

}

0 comments on commit 554febd

Please sign in to comment.