Skip to content
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: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ Bug Fixes to Attribute Support
- Fix handling of parameter indexes when an attribute is applied to a C++23 explicit object member function.
- Fixed several false positives and false negatives in function effect (`nonblocking`) analysis. (#GH166078) (#GH166101) (#GH166110)
- Fix ``cleanup`` attribute by delaying type checks until after the type is deduced. (#GH129631)
- Fix a crash when instantiating a function template with ``constructor`` or ``destructor``
attributes without a priority argument. (#GH169072)

Bug Fixes to C++ Support
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
20 changes: 11 additions & 9 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,17 @@ static void sharedInstantiateConstructorDestructorAttr(
ExprResult Result = S.SubstExpr(A->getPriority(), TemplateArgs);
if (Result.isInvalid())
return;
tempInstPriority = Result.get();
if (std::optional<llvm::APSInt> CE =
tempInstPriority->getIntegerConstantExpr(C)) {
// Consistent with non-templated priority arguments, which must fit in a
// 32-bit unsigned integer.
if (!CE->isIntN(32)) {
S.Diag(tempInstPriority->getExprLoc(), diag::err_ice_too_large)
<< toString(*CE, 10, false) << /*Size=*/32 << /*Unsigned=*/1;
return;
if (Result.isUsable()) {
tempInstPriority = Result.get();
if (std::optional<llvm::APSInt> CE =
tempInstPriority->getIntegerConstantExpr(C)) {
// Consistent with non-templated priority arguments, which must fit in a
// 32-bit unsigned integer.
if (!CE->isIntN(32)) {
S.Diag(tempInstPriority->getExprLoc(), diag::err_ice_too_large)
<< toString(*CE, 10, false) << /*Size=*/32 << /*Unsigned=*/1;
return;
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions clang/test/SemaTemplate/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,23 @@ namespace preferred_name {
Foo<1, 2, int, float>::nosuch x; // expected-error {{no type named 'nosuch' in 'preferred_name::Bar<int, float>'}}
}
::preferred_name::Foo<1, 2, int, float>::nosuch x; // expected-error {{no type named 'nosuch' in 'preferred_name::Bar<int, float>'}}

// GH169072: templated attribute((constructor)) function crashes clang
// constructor/destructor attribute without priority argument should not crash.
namespace gh169072 {
template <typename T>
[[gnu::constructor]] void foo() {}

template void foo<int>();

template <typename T>
[[gnu::destructor]] void bar() {}

template void bar<int>();

// Also test with explicit priority argument
template <typename T>
[[gnu::constructor(101)]] void baz() {}

template void baz<int>();
}