Skip to content

[Clang] Fix some assertions not looking through type sugar #92299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}}

}
Loading