Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

typeid() does not yield a compile-time constant address #20289

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR20290
Status NEW
Importance P normal
Reported by David Krauss (david_work@me.com)
Reported on 2014-07-13 03:26:20 -0700
Last modified on 2014-07-14 16:40:33 -0700
Version 3.4
Hardware PC All
CC dgregor@apple.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

static_assert ( & typeid( int ) == & typeid( int ), "" );

As far as I can see, this is valid C++11, and nothing changes for the latest C++14 draft. It does not include any id-expression, lvalue-to-rvalue conversion, nor a typeid with polymorphic operand.

Such a construct would provide value-based compile time type identity. GCC accepts it.

Quuxplusone commented 10 years ago
From my reply on std-proposals:

It is unspecified whether those two typeid expressions produce glvalues
referring to the same object. Therefore this is "a relational or equality
operator where the result is unspecified", so it's non-constant per 5.19/2
bullet 19.

Clang is not deliberately giving this result; I didn't think of this case when
implementing support for typeid expressions in constexpr evaluation. Indeed,
Clang gives the opposite result for this:

constexpr const std::type_info &x() { return typeid(int); }
static_assert(&x() == &x(), "");

... which is arguably ill-formed for the same reason.

We should at least be consistent here; I've also mailed CWG to see if there's
consensus for a less surprising rule here.