<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112859>112859</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Different ODR-usage between 'auto' and 'decltype' when declaring a static constexpr member.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
LaicepS
</td>
</tr>
</table>
<pre>
Hello,
Let's say I have a template class with a member function which is not ODR-used. Clang will remove it from its AST, to avoid that, I reference it in a constexpr static variable:
```c++
template<typename T>
struct foo_t {
int a() { return 42; }
static constexpr auto __a = &foo_t::a;
};
int main() {
foo_t<int> f;
}
```
Now replace 'auto' with a 'decltype':
```diff
--- with_auto.cpp 2024-10-18 11:02:43.389178174 +0200
+++ with_decltype.cpp 2024-10-18 11:02:51.985095752 +0200
@@ -4,3 +4,3 @@
- static constexpr auto __a = &foo_t::a;
+ static constexpr decltype(&foo_t::a) __a = &foo_t::a;
};
```
And compare the AST of the `-ClassTemplateSpecializationDecl` with `clang++ -Xclang -ast-dump <file>`:
With "auto", the function has a body:
```
| |-CXXMethodDecl 0x77f9ae0 <line:3:3, col:24> col:7 used a 'int ()' implicit_instantiation implicit-inline instantiated_from 0x77f9378
| | `-CompoundStmt 0x781a0e8 <col:11, col:24>
| | `-ReturnStmt 0x781a0d8 <col:13, col:20>
| | `-IntegerLiteral 0x77f95e8 <col:20> 'int' 42
```
But the body is absent when using `decltype`:
```
| |-CXXMethodDecl 0x71bdeb0 <line:3:3, col:24> col:7 referenced a 'int ()' implicit_instantiation implicit-inline instantiated_from 0x71bd6c8
```
Is it an expected behavior?
Best regards and thank you for the great work!
Dorian
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVkFv2zgT_TX0ZSCDpGxLOvhgyw2-AP12gabA9haMpJHFrUQKJGU3--sXpOzYSYtusVhAURhS8-bNzJth0Dl11ERbtt6z9WG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