[clang] [Clang] Fix nonblocking warning for dependent default arguments (PR #235457)

Chen Miao via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 6 23:31:26 PST 2026


================
@@ -1342,6 +1342,14 @@ class Analyzer {
       return Result;
     }
 
+    bool TraverseParmVarDecl(ParmVarDecl *D) override {
+      // Uninstantiated default arguments are dependent expressions that cannot
+      // be analyzed for function effects without producing incorrect warnings.
----------------
ChenMiaoi wrote:

@ojhunt In this example, `h(x)` supplies an argument, so I would expect `bad()` in `T = bad()` not to be called. Does that mean `h(x)` should not produce a warning? I’m not entirely sure. CC @Sirraide for review, as a maintainer.

``` cc
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}}
}
```

https://github.com/llvm/llvm-project/pull/235457


More information about the cfe-commits mailing list