You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Out-of-line initialization of static const member arrays doesn't work, and wrongly requires static const at definition site #5823
I think this is because static outside of the class makes no sense in C++ (and for LLVM), but I cannot use const on its own because I get a different problem.
where the InitListExpr is being marked as being of type 'void'. This tracks with the error message that I get from my local build:
error: casting to type 'void' unimplemented
Chris B (@llvm-beanz) is this AST correct for the given code? Do you know if it would be better to change the AST or to change the SPIR-V backend to use the type that the InitListExpr is being assigned to?
<source>:14:28: error: 'const' is not a valid modifier for a field
template<typename float_t> const float_t GaussLegendreValues<2,float_t>::wi[2] = {1.0, 1.0};
So the error is that we don't get a diagnostic of trying to use static on a class/struct member outside the class definition, and that we get an error and a diagnostic when attempting to do the "right thing" (TM).
changed the title [-][SPIR-V] Out-of-line initialization of `static const` member arrays of templated types SIGSEGVs[/-][+]Out-of-line initialization of `static const` member arrays doesn't work, and wrongly requires `static const` at definition site[/+]on Dec 10, 2025
devshgraphicsprogramming commented on Dec 10, 2025
<source>:15:37: error: redeclaration of 'wi' with a different type: 'float [2]' vs 'const float [2]'
float GaussLegendreValues<2,float>::wi[2] = {1.0, 1.0};
^
<source>:15:37: note: previous declaration is here
All happens without -spirv as well.
devshgraphicsprogramming commented on Dec 10, 2025
Activity
sudonatalie commentedon Oct 17, 2023
Thanks for reporting. Assigning to Cassandra Beckley (@cassiebeckley) to take a look.
cassiebeckley commentedon Oct 19, 2023
I think this might actually be a parser or Sema bug. The AST I get for this code using
-ast-dumpisThe relevant portion is
where the
InitListExpris being marked as being of type'void'. This tracks with the error message that I get from my local build:Chris B (@llvm-beanz) is this AST correct for the given code? Do you know if it would be better to change the AST or to change the SPIR-V backend to use the type that the
InitListExpris being assigned to?llvm-beanz commentedon Oct 19, 2023
I can't say that I understand it, but clang gives
InitListExprtypevoidfor C++ too:https://godbolt.org/z/oKrhbYGrn
So I think that bit is right.
cassiebeckley commentedon Oct 19, 2023
Huh, interesting. Thanks for pointing that out, I'll update the backend then.
devshgraphicsprogramming commentedon Jun 4, 2024
Btw it works for non-array types
https://godbolt.org/z/9G7vnhesr
and on this simple repro
https://godbolt.org/z/ze8jaoM3z
But this is a full explicit specialization out of line initialization, not a partial.
5 remaining items
devshgraphicsprogramming commentedon Dec 10, 2025
Now the original thing has a useful error
https://godbolt.org/z/14badfxqE
Btw I don't get one thing, in c++20 for out of line
consexprdeclarations, I'd useconst staticat the member declaration.and then for the out-of line definitition
constexprorconstexpr inlinedepending on the linkage I wanthttps://godbolt.org/z/sr9vh3Gbb
For obvious reasons in HLSL I need to use just
constfor the OOL definition.With C++ it actually results in the same codegen if I don't do any exporting or linking
https://godbolt.org/z/W3cnYjqb1
Our repro was always wrong
and compiler should emit a diagnostic like C++ https://godbolt.org/z/M9hajz5eE
instead I get
But then if I try to use the "correct" thing, we have https://godbolt.org/z/fExjP8rEM
So the error is that we don't get a diagnostic of trying to use
staticon a class/struct member outside the class definition, and that we get an error and a diagnostic when attempting to do the "right thing" (TM).Natalie Chouinard (@sudonatalie) I see that Cassandra Beckley (@cassiebeckley) has left Google, is there chance anyone else gets assigned to this?
[-][SPIR-V] Out-of-line initialization of `static const` member arrays of templated types SIGSEGVs[/-][+]Out-of-line initialization of `static const` member arrays doesn't work, and wrongly requires `static const` at definition site[/+]devshgraphicsprogramming commentedon Dec 10, 2025
Changed the title to reflect that it also affects DXIL
https://godbolt.org/z/6fnGf8f6q
It also doesn't fork on full specializations
https://godbolt.org/z/8TzvPPE3Y
It will give the same diagnostic even if you don't add
cosnt(which you should) and misform the templatehttps://godbolt.org/z/xredxYY3x
And on a correctly formed full explicit specialization
https://godbolt.org/z/3e3veWxsc
funnily enough if you remove the
const(to make it malformed) it gives diagnostics that make sensehttps://godbolt.org/z/6f3h4a99c
All happens without
-spirvas well.devshgraphicsprogramming commentedon Dec 10, 2025
The fun part is that as soon as we remove the templating, we get expected behaviour
constwithoutstaticin OOL initializationhttps://godbolt.org/z/WvdKs7KnM
However its a bit disappointing that
const staticon the OOL is acceptedhttps://godbolt.org/z/hW1z876cW
[SPIR-V] Fix crash with out-of-line template decl
[SPIR-V] Fix crash with out-of-line template decl
[SPIR-V] Fix crash with out-of-line template decl (microsoft#8079)
devshgraphicsprogramming commentedon Feb 24, 2026
Nathan Gauër (@Keenuts) I don't get why the issue is closed if all the repros I gave still fail ?
Keenuts commentedon Feb 24, 2026
They do? In this case we can re-open.
devshgraphicsprogramming commentedon Feb 24, 2026
first thing is that DXC wants me to use
static constat the OOL definition site, when it should be justconst#5823 (comment)
second is that I can't OOL define members of a templated struct, even with explicit instantiation