Is it ever possible that in the following setup
template <typename T>
inline void id() {
//...
}
template <typename T>
bool check() {
return &id<T> == &id<T const>;
}
check will return true for some T? Does it depend on what is being done inside id? What does the standard have to say about this?
Sure. Try
const intorint&orvoid().There’s a rule that top-level
constqualifiers collapse if you get multiple of them through atypedefor a template argument, which meanscheck<int const>()will returntrue.[normative text pending]
Then there’s a rule that ignores top-level
conston things it doesn’t work on, like references or function types. That meanscheck<int&>andcheck<int()>will returntrue.§8.3.2 [dcl.ref] p1and
§4.4 [conv.qual] p3§8.5.3 [dcl.fct] p6