[clang] [Sema] Don't call isNonConstantStorage on incomplete variable types (PR #161590)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 3 11:23:47 PDT 2025
================
@@ -14919,7 +14919,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
// Apply section attributes and pragmas to global variables.
if (GlobalStorage && var->isThisDeclarationADefinition() &&
- !inTemplateInstantiation()) {
+ !var->getDeclContext()->isDependentContext()) {
----------------
erichkeane wrote:
Checking JUST the actual var decl is actually going to be a 'smaller' thing, but I'm not sure it is actually going to work? @ahatanak : please try it though, it is quite a bit easier.
The difference here is that if we switch to ONLY a dependent type (instead of a dependent decl), we end up in a situation where we might try to do this for a non-dependently typed variable in a dependent context. So I don't think that'll fix it?
Consider the example:
```
template <class T>
struct A {
struct B;
static constexpr B b{nullptr}; // This used to crash.
};
```
IN this case, `B` is a dependent type, since it is inside the struct (so it is `A<T>::B`. However consider this slight modification (please add this test!).
```
struct B;
template <class T>
struct A {
static constexpr B b{nullptr}; // This used to crash.
};
```
Note I moved `B` out of the template. Now `b` is still going to go down this path (I think?) but is no longer a dependent type, despite being a dependent context. I think this is wrong?
https://github.com/llvm/llvm-project/pull/161590
More information about the cfe-commits
mailing list