3 ms·
There is no ODR violation in this itself either: template<class T> class S { public: // template<std::enable_if_t<((void)sizeof(T), true), bool> = fa
by steerablesafe 5y ago
There is no ODR violation in this itself either:
template<class T>
class S {
public:
// template<std::enable_if_t<((void)sizeof(T), true), bool> = false>
explicit S(unsigned char *) {
static_assert(sizeof(T) > 0, "oops");
}
};
It was always about usage. Some constructs are easier to misuse than others.
- dataflow 5y agoMine was indeed about usage; I'm pretty sure I never claimed there's any ODR violation in that code. Whereas in your comment you specifically claimed "the different value for `is_constructible_v<S<X>>` can cause ODR violation in this variable template itself https://eel.is/c++draft/meta#rqmts-5 https://eel.is/c++draft/meta#rqmts-5", in response to which I pointed out that the quote you're referencing declares this UB without involving ODR at all. In any case, I think we're on the same page at this point; we both understand the issues and risks/benefits with both approaches. Hope the examples I provided were helpful.
- steerablesafe 5y agoYes, the quote for [meta] only specifies UB (although it should arguably be IFNDR). If yourself implemented `your::is_constructible_v`, then in translation units it instantiated differently for the same template arguments, then it would be ODR-violation according to https://eel.is/c++draft/temp.point#7.sentence-4 https://eel.is/c++draft/temp.point#7.sentence-4 .
- dataflow 5y agoFunny enough, I am actually not sure if even that is true in the way you're imagining. Bear in mind such a variable would be a constexpr inline template... which would be kind of its entire point. To violate ODR with it you'd not only have to implement your::is_constructible_v, but also use the resulting value in a non-constexpr context (I think [1] alludes to this)... which would be a rather bizarre use for a type trait called 'is_constructible_v'. Anyway, this discussion is dragging on forever, so I'm just gonna stop here and wrap this up with the following: As I see it, the only realistic way you could ever generate a buggy program with this is if you're getting nerd-sniped and desperately trying to come up with a counterexample in response to someone's challenge on HN. For practical purposes I see it as a non-issue. [1] https://eel.is/c++draft/basic.def.odr#5 https://eel.is/c++draft/basic.def.odr#5