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

            Bug ID: 102916
           Summary: cmath constexpr can lead to ODR violations/incorrect
                    results
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Darrell.Wright at gmail dot com
  Target Milestone: ---

Because many of the cmath functions are constexpr, even in conformance mode of
the compiler, this can lead to ODR issues.  It is detectable in C++20 and gives
incorrect results.

#include <cmath>

template<auto F>
consteval auto foo( ) {
  if constexpr (requires {
                  []<int>() {}.template operator()<(F(), void(), 0)>();
                }) {
                        return 0;
  } else { 
                return 1;
        }
}


auto a = foo<[]{ return std::sqrt( 4.0 ); }>( );

https://gcc.godbolt.org/z/M6zGTbTfM


gcc returns 0, clang/libstdc++ and MSVC return 1.

I believe that in conformance -std=c++20 -pedantic mode that gcc should not
mark these methods as constexpr

Reply via email to