[clang] [Clang] Fix nonblocking warning for dependent default arguments (PR #235457)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 18:56:08 PST 2026
https://github.com/ojhunt requested changes to this pull request.
At most you should only be skipping the default argument expression, it's possible that an early return that still forwards to `VisitVarDecl` might also be ok, but I'm not super sure.
In addition the comments about what the change is doing are wrong
I also spent some time trying to work out what would go wrong and there are a few diagnostic regressions (shown through `bin/clang++ -fsyntax-only -Wfunction-effects -Xclang -verify file.cpp`).
```cpp
#define __nonblocking [[clang::nonblocking]]
struct Foo {
~Foo(); // #FooDestructor
// expected-note at -1 5 {{declaration cannot be inferred 'nonblocking' because it has no definition in this translation unit}}
};
template <typename T> void g1(T,
Foo = Foo() // #g1FooParameter
) __nonblocking {}
template <typename T>
void g2(T,
Foo // #g2FooParameter
) __nonblocking {} // #g2DeclEnd
void use(Foo &f) {
// Regressed: no diagnostics
g1(1, f);
// expected-warning@#g1FooParameter 2 {{function with 'nonblocking' attribute must not call non-'nonblocking' destructor}}
// expected-note at -2 2 {{in template expansion here}}
g2(1, f);
// expected-warning@#g2DeclEnd {{function with 'nonblocking' attribute must not call non-'nonblocking' destructor}}
// expected-note at -2 {{in template expansion here}}
}
// A reference for g1 and g2: a non-dependent default parameter causes two diagnostics
void g_reference(int, Foo = Foo()) __nonblocking {}
// expected-warning at -1 2 {{function with 'nonblocking' attribute must not call non-'nonblocking' destructor}}
int bad(); // #BadDecl
// expected-note at -1 {{declaration cannot be inferred 'nonblocking' because it has no definition in this translation unit}}
template <typename T>
int h(
T = bad() // #hParam
) __nonblocking { return 0; }
void h1(int x) {
// These warnings are now only triggered if there is a separate call h() with
// the template parameter specified explicitly.
// Note: the warnings occur on this call even though the call to h<int>() is
// later in the file.
h(x);
// expected-warning@#hParam {{function with 'nonblocking' attribute must not call non-'nonblocking' function 'bad'}}
// expected-note at -2 {{in template expansion here}}
}
// make this `1` for the above diagnostics to be restored.
#if 0
void h2() {
h<int>();
}
#endif
```
https://github.com/llvm/llvm-project/pull/235457
More information about the cfe-commits
mailing list