https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125886

            Bug ID: 125886
           Summary: std::declval in unevaluated typeid operand incorrectly
                    triggers __declval_protector
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vladislav.semykin at gmail dot com
  Target Milestone: ---

For [expr.typeid]/5 (https://eel.is/c++draft/expr.typeid#5) typeid applied to a
non-polymorphic expression has an unevaluated operand. Per [utility.declval],
std::declval is only required to be valid in unevaluated operands - which is
satisfied here.

GCC incorrectly instantiates the body of std::declval, triggering
__declval_protector's static_assert. Clang 19.1.0 and MSVC 19.51 accept this
code.

#include <typeinfo> // for `typeid`
#include <utility>  // for `std::declval`

class A_class{};

void foo()
{
    char const *a = typeid(std::declval<A_class>()).name();
}

Reproducer: https://godbolt.org/z/1jYb6MGvj
See also: bug 116385

I would be happy to work on a fix!

Reply via email to