non-constexpr recursive variable templates are instanciated wrongly
| Bugzilla Link | 29033 |
| Resolution | DUPLICATE |
| Resolved on | Mar 09, 2021 10:10 |
| Version | 3.8 |
| OS | Linux |
| Attachments | Code generated by clang++ -std=c++14 -Wall -Wextra -pedantic -S |
| CC | @zygoloid |
Extended Description
The following code:
#include
template<std::size_t N>
auto fibo_v{fibo_v
template<> auto fibo_v<0>{0};
template<> auto fibo_v<1>{1};
int main() { std::cout << fibo_v<4> << '\n'; }
produces 0 as its output. Adding constexpr to the variable declarations resolves this and produces the correct result 3.
As far as i can tell, N3651 lifted the restriction on variable templates to be constexpr, thus i would expect the same result with and without constexpr in the declarations.
GCC 6.1.1 produces the correct output, regardless of constexpr being in place or not.
mentioned in issue llvm/llvm-bugzilla-archive#49458
mentioned in issue llvm/llvm-bugzilla-archive#49458
Not a bug: implicit instantiations of a variable template have unordered initialization. There is no guarantee that fibo_v<3> and fibo_v<2> are initialized before fibo_v<4>.
*** This bug has been marked as a duplicate of bug llvm/llvm-bugzilla-archive#49458 ***