[llvm-bugs] [Bug 51290] New: AST not generated for static constexpr member variable value for c++17 (is for c++14)
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jul 31 01:02:37 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51290
Bug ID: 51290
Summary: AST not generated for static constexpr member variable
value for c++17 (is for c++14)
Product: clang
Version: 12.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++17
Assignee: unassignedclangbugs at nondot.org
Reporter: bensan.morris at googlemail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
Hi,
For the following code snippet:
// snippet.h
template<int X>
class T {
static constexpr int Y = X;
};
T<42> foo;
I run it under clang-check dumping AST for c++14 vs 17:
// clang-check (c++14)
/usr/bin/clang-check-12 --extra-arg-before=-xc++ --extra-arg-before=-std=c++14
snippet.h --ast-dump &> 14.txt
// clang-check (c++17)
/usr/bin/clang-check-12 --extra-arg-before=-xc++ --extra-arg-before=-std=c++17
snippet.h --ast-dump &> 17.txt
And then diff:
// diff 14.txt 17.txt
...
44,57c44,53
< | |-CXXRecordDecl 0x13ee6b8 prev 0x13ee418 <col:1, col:7> col:7 implicit
class T
< | |-VarDecl 0x13ee748 <line:3:4, col:29> col:25 Y 'const int' static
constexpr cinit
< | | |-value: Int 42 <-- WORKS UNDER 14
< | | `-SubstNonTypeTemplateParmExpr 0x13ee7e0 <col:29> 'int'
< | | |-NonTypeTemplateParmDecl 0x13edf28 <line:1:10, col:14> col:14
referenced 'int' depth 0 index 0 X
< | | `-IntegerLiteral 0x13ee7c0 <line:3:29> 'int' 42
< | |-CXXConstructorDecl 0x13ee888 <line:2:7> col:7 implicit used constexpr T
'void () noexcept' inline default trivial
< | | `-CompoundStmt 0x13eed18 <col:7>
< | |-CXXConstructorDecl 0x13ee9b8 <col:7> col:7 implicit constexpr T 'void
(const T<42> &)' inline default trivial noexcept-unevaluated 0x13ee9b8
< | | `-ParmVarDecl 0x13eeac8 <col:7> col:7 'const T<42> &'
< | `-CXXConstructorDecl 0x13eeb68 <col:7> col:7 implicit constexpr T 'void
(T<42> &&)' inline default trivial noexcept-unevaluated 0x13eeb68
< | `-ParmVarDecl 0x13eec78 <col:7> col:7 'T<42> &&'
< `-VarDecl 0x13ee5a0 <line:5:1, col:7> col:7 foo 'T<42>':'T<42>' callinit
< `-CXXConstructExpr 0x13eed28 <col:7> 'T<42>':'T<42>' 'void () noexcept'
---
> | |-CXXRecordDecl 0x1d3cc78 prev 0x1d3c9d8 <col:1, col:7> col:7 implicit class T
> | |-VarDecl 0x1d3cd08 <line:3:4, col:25> col:25 Y 'const int' static constexpr
<-- MISSING VALUE UNDER 17
> | |-CXXConstructorDecl 0x1d3cdb0 <line:2:7> col:7 implicit used constexpr T 'void () noexcept' inline default trivial
> | | `-CompoundStmt 0x1d3d248 <col:7>
> | |-CXXConstructorDecl 0x1d3cee8 <col:7> col:7 implicit constexpr T 'void (const T<42> &)' inline default trivial noexcept-unevaluated 0x1d3cee8
> | | `-ParmVarDecl 0x1d3cff8 <col:7> col:7 'const T<42> &'
> | `-CXXConstructorDecl 0x1d3d098 <col:7> col:7 implicit constexpr T 'void (T<42> &&)' inline default trivial noexcept-unevaluated 0x1d3d098
> | `-ParmVarDecl 0x1d3d1a8 <col:7> col:7 'T<42> &&'
> `-VarDecl 0x1d3cb60 <line:5:1, col:7> col:7 foo 'T<42>':'T<42>' callinit
> `-CXXConstructExpr 0x1d3d258 <col:7> 'T<42>':'T<42>' 'void () noexcept'
Under 14 AST for static constexpr Y member is generated with value (42) however
17 generates decl only (no value).
If I then modify snippet as follows:
(modified snippet.h)
template<int X>
class T {
static constexpr int Y = X;
T()
{
auto tmp = Y;
}
};
T<42> foo;
Y's value is generated in AST for c++17. Is this a bug in clang or something we
are not doing correctly wrt C++ standard?
This issue was originally mentioned in a stack overflow post (so kudos to the
original author for identifying the workaround for clang AST generation under
17 for this scenario):
https://stackoverflow.com/questions/60308864/accessing-the-initializer-of-a-static-constexpr-in-llvm-c17
Many thanks in advance,
Ben.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210731/51b54725/attachment-0001.html>
More information about the llvm-bugs
mailing list