zygoloid wrote:

GCC accepts both, but that doesn't really tell us what's going on. It's 
probably more interesting to look at things like whether `typename` is 
required, eg:

https://godbolt.org/z/z8hnh6rK8 (references: don't need `typename`)
https://godbolt.org/z/rsjx3c6v9 (pointers: need `typename`)

Clang and GCC agree here: the `&` syntax makes the expression value-dependent, 
and the same thing done with references is not value-dependent.

> I can't think of a good reason why the two should have different behaviors.

Yeah, I agree. This looks pretty strange.

Looking at

https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1413
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2100

it seems like the intent was to make an expression that depends on an 
instantiation-dependent address be value-dependent, while treating 
id-expressions as non-dependent if they name a templated variable with a 
non-dependent constant initializer and only use it for its value. Eg, this 
should not require `typename`:

```c++
template<int> struct Y { struct Z {}; };
template <typename T> struct S {
    static constexpr int x = 42;
    Y<x>::Z z = Y<x>::Z();
};
S<int> s;
```
but this should:
```c++
template<const int*> struct Y { struct Z {}; };
template <typename T> struct S {
    static constexpr int x = 42;
    Y<&x>::Z z = Y<&x>::Z();
};
S<int> s;
```

This is all quite old wording; I think the modern C++ rules, the right thing to 
do would be to use the "named only for its value" logic that lives in 
[[basic.def.odr]](https://eel.is/c++draft/basic.def.odr#5.sentence-2). Perhaps 
we could simply say that an id-expression that odr-uses a templated entity is 
value-dependent. (In Clang's model, we'd look at `isNonOdrUse` on the 
`DeclRefExpr`.)

Maybe worth filing a core issue at https://github.com/cplusplus/CWG?

https://github.com/llvm/llvm-project/pull/211706
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to