Created attachment 42228 [details] The code have a bug Hello to GCC ( g++ ) developers! My English is bad, but i hope you will understand me. I found a bug ( if it is ) in g++ 6.4.0 version ( and earlier ). I will just provide a code which have the bug: /* Begin */ #include <iostream> enum : unsigned long long { VAL }; void foo( unsigned long long ) { std::cout << "unsigned long long" << std::endl; } void foo( int ) { std::cout << "int" << std::endl; } int main( void ) { foo( VAL ); } /* End */ I compiled this code in a Unix-like environment and command-line interface for Microsoft Windows -- Cygwin ( 64-bit ). I used following compiler options: -Wall -Wextra -std=c++17 <path_to_file.cpp> The following error messages were displayed: C:\Users\Maxim\Desktop\test.cpp: In function ‘int main()’: C:\Users\Maxim\Desktop\test.cpp:19:14: error: call of overloaded ‘foo(<anonymous enum>)’ is ambiguous foo( VAL ); ^ C:\Users\Maxim\Desktop\test.cpp:6:6: note: candidate: void foo(long long unsigned int) void foo( unsigned long long ) ^~~ C:\Users\Maxim\Desktop\test.cpp:11:6: note: candidate: void foo(int) void foo( int ) ^~~ ---- Thank you.
clang accepts it.
(In reply to Richard Biener from comment #1) > clang accepts it. Yes, I know. I would like to know if the g++ is deviating from the standard, that nothing is written about it, or will it be fixed?
The bug status was changed to NEW, that means it's been confirmed as a GCC bug that should be fixed. Richard was noting for other people's benefit that Clang accepts the code.
This seems to be a problem in integral promotion in function type_promotes_to(). The following change fixes the bug: --- gcc/cp/cvt.c (revision 253270) +++ gcc/cp/cvt.c (working copy) @@ -1854,11 +1854,15 @@ tree prom = type; if (TREE_CODE (prom) == ENUMERAL_TYPE) prom = ENUM_UNDERLYING_TYPE (prom); - if (TYPE_UNSIGNED (prom) - && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype)) - prom = c_common_type_for_size (precision, 1); - else - prom = totype; + // If enum has fixed underlying type, use that type (bug 82307) + if (!ENUM_FIXED_UNDERLYING_TYPE_P (type)) + { + if (TYPE_UNSIGNED (prom) + && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype)) + prom = c_common_type_for_size (precision, 1); + else + prom = totype; + } if (SCOPED_ENUM_P (type)) { if (abi_version_crosses (6)
Mukesh is on it.
Submitted fix: https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00524.html
Author: paolo Date: Tue Oct 24 13:49:13 2017 New Revision: 254046 URL: https://gcc.gnu.org/viewcvs?rev=254046&root=gcc&view=rev Log: /cp 2017-10-24 Mukesh Kapoor <mukesh.kapoor@oracle.com> Paolo Carlini <paolo.carlini@oracle.com> PR c++/82307 * cvt.c (type_promotes_to): Implement C++17, 7.6/4, about unscoped enumeration type whose underlying type is fixed. /testsuite 2017-10-24 Mukesh Kapoor <mukesh.kapoor@oracle.com> Paolo Carlini <paolo.carlini@oracle.com> PR c++/82307 * g++.dg/cpp0x/enum35.C: New. * g++.dg/cpp0x/enum36.C: Likewise. Added: trunk/gcc/testsuite/g++.dg/cpp0x/enum35.C trunk/gcc/testsuite/g++.dg/cpp0x/enum36.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cvt.c trunk/gcc/testsuite/ChangeLog
Fixed.