public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102916] New: cmath constexpr can lead to ODR violations/incorrect results
@ 2021-10-24 17:27 Darrell.Wright at gmail dot com
  2021-10-24 19:24 ` [Bug c++/102916] " pinskia at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Darrell.Wright at gmail dot com @ 2021-10-24 17:27 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-05-21  3:46 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 17:27 [Bug c++/102916] New: cmath constexpr can lead to ODR violations/incorrect results Darrell.Wright at gmail dot com
2021-10-24 19:24 ` [Bug c++/102916] " pinskia at gcc dot gnu.org
2021-10-24 19:57 ` Darrell.Wright at gmail dot com
2021-10-24 20:18 ` Darrell.Wright at gmail dot com
2021-10-24 20:30 ` pinskia at gcc dot gnu.org
2021-10-24 20:34 ` pinskia at gcc dot gnu.org
2021-10-24 20:41 ` [Bug libstdc++/102916] " Darrell.Wright at gmail dot com
2021-10-25  8:32 ` redi at gcc dot gnu.org
2021-10-25  8:35 ` redi at gcc dot gnu.org
2021-10-25  9:32 ` redi at gcc dot gnu.org
2021-10-25  9:34 ` redi at gcc dot gnu.org
2021-10-25 13:29 ` Darrell.Wright at gmail dot com
2022-11-30 14:52 ` redi at gcc dot gnu.org
2022-11-30 14:53 ` redi at gcc dot gnu.org
2024-05-21  3:46 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).