public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers)
@ 2011-11-26 15:16 tsoae at mail dot ru
  2011-11-26 15:33 ` [Bug c++/51312] " marc.glisse at normalesup dot org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: tsoae at mail dot ru @ 2011-11-26 15:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51312

             Bug #: 51312
           Summary: Wrong interpretation of converted constant expressions
                    (for template arguments and enumerator initializers)
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tsoae@mail.ru


GNU C++ 4.7.0 fails to compile the following well-defined code:

    struct X
    {
        constexpr operator int()
            { return true; }
    };

    template <int>
        struct A {};

    int main()
    {
        // error: expected a constant of type 'int', got 'X()'
        A<X()>();

        // error: enumerator value for 'e' is not an integer constant
        enum : int { e = X() };
    }

In both cases a converted constant expression of type int is required (see
14.3.2/1/1 and 7.2/5). According to 5.19/3, X() can be used in a context where
a converted constant expression of type int is required.


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

* [Bug c++/51312] Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
@ 2011-11-26 15:33 ` marc.glisse at normalesup dot org
  2011-11-26 17:32 ` tsoae at mail dot ru
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: marc.glisse at normalesup dot org @ 2011-11-26 15:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51312

Marc Glisse <marc.glisse at normalesup dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marc.glisse at normalesup
                   |                            |dot org

--- Comment #1 from Marc Glisse <marc.glisse at normalesup dot org> 2011-11-26 15:15:34 UTC ---
For the first one, you should write X{} instead of X() which looks too much
like a function type. The second one is more surprising.


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

* [Bug c++/51312] Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
  2011-11-26 15:33 ` [Bug c++/51312] " marc.glisse at normalesup dot org
@ 2011-11-26 17:32 ` tsoae at mail dot ru
  2012-01-30 22:15 ` [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for " pinskia at gcc dot gnu.org
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: tsoae at mail dot ru @ 2011-11-26 17:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51312

--- Comment #2 from Nikolka <tsoae at mail dot ru> 2011-11-26 15:33:36 UTC ---
> For the first one, you should write X{} instead of X() which looks too much
like a function type.

I agree, that was my mistake.


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
  2011-11-26 15:33 ` [Bug c++/51312] " marc.glisse at normalesup dot org
  2011-11-26 17:32 ` tsoae at mail dot ru
@ 2012-01-30 22:15 ` pinskia at gcc dot gnu.org
  2012-02-08 20:20 ` pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-01-30 22:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51312

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-01-30
     Ever Confirmed|0                           |1

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-30 21:39:04 UTC ---
Interesting because:
        A<X{}>();

is accepted now on the trunk but:
        enum : int { e = X{} };
is rejected.
Also 
        A<X()>();
is still rejected.

So confirmed.


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (2 preceding siblings ...)
  2012-01-30 22:15 ` [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for " pinskia at gcc dot gnu.org
@ 2012-02-08 20:20 ` pinskia at gcc dot gnu.org
  2012-04-29 14:12 ` marc.glisse at normalesup dot org
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-08 20:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51312

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |27403

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-08 20:19:45 UTC ---
I think this is related to PR 27403.


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (3 preceding siblings ...)
  2012-02-08 20:20 ` pinskia at gcc dot gnu.org
@ 2012-04-29 14:12 ` marc.glisse at normalesup dot org
  2014-07-12 19:57 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: marc.glisse at normalesup dot org @ 2012-04-29 14:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51312

--- Comment #5 from Marc Glisse <marc.glisse at normalesup dot org> 2012-04-29 14:12:12 UTC ---
Created attachment 27261
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27261
build_enumerator patch

Changes the behavior on g++.dg/cpp0x/enum_base.C from an error to a warning in
the first 2 cases. And reusing the narrowing warning message may look a bit
strange.

enum E4 : char { 
  val = 500 // { dg-error "too large" }
};

enum_base.C:9:9: warning: narrowing conversion of '500' from 'int' to 'char'
inside { } [-Wnarrowing]
   val = 500 // { dg-error "too large" }
         ^
enum_base.C:9:9: warning: overflow in implicit constant conversion [-Woverflow]
   val = 500 // { dg-error "too large" }
         ^


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (4 preceding siblings ...)
  2012-04-29 14:12 ` marc.glisse at normalesup dot org
@ 2014-07-12 19:57 ` paolo.carlini at oracle dot com
  2014-07-13  8:54 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-12 19:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Marc, are you going to send your patch to the mailing list (CC Jason)? I note
that current clang too for enum_base.C issues the narrowing diagnostic: as-is
patch seems already pretty good to me.


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (5 preceding siblings ...)
  2014-07-12 19:57 ` paolo.carlini at oracle dot com
@ 2014-07-13  8:54 ` paolo.carlini at oracle dot com
  2014-07-13  9:17 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-13  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Uhm, it occurs to me that we may also play with moving up the code we already
have a few line below handling ENUM_UNDERLYING_TYPE (enumtype): if convert is
called first on the X() in e = X() we get a CALL_EXPR from a TARGET_EXPR, which
then cxx_constant_value is able to handle...


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (6 preceding siblings ...)
  2014-07-13  8:54 ` paolo.carlini at oracle dot com
@ 2014-07-13  9:17 ` paolo.carlini at oracle dot com
  2014-07-22 10:01 ` glisse at gcc dot gnu.org
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-13  9:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> ---
... but then value isn't yet an INTEGER_CST and we can't use int_fits_type_p...
 Still, something seems redundant between an early conversion and the final
convert.


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (7 preceding siblings ...)
  2014-07-13  9:17 ` paolo.carlini at oracle dot com
@ 2014-07-22 10:01 ` glisse at gcc dot gnu.org
  2014-07-31 13:26 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-07-22 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Paolo Carlini from comment #6)
> Marc, are you going to send your patch to the mailing list (CC Jason)?

Sorry, I don't remember this patch at all. I may try again to understand what
it does at some point, but you seem to have a much better understanding of what
is going on, so don't hesitate to take this bug.


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (8 preceding siblings ...)
  2014-07-22 10:01 ` glisse at gcc dot gnu.org
@ 2014-07-31 13:26 ` paolo.carlini at oracle dot com
  2014-08-06 19:46 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-31 13:26 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com

--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Ah Ok...


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (9 preceding siblings ...)
  2014-07-31 13:26 ` paolo.carlini at oracle dot com
@ 2014-08-06 19:46 ` paolo.carlini at oracle dot com
  2014-08-07  0:02 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-08-06 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I'm having a look at the issue and it seems rather different than I (we)
thought. Suffices to say that it does not affect constexpr non-operator member
functions, and that sort-of explains this (ugly) workaround:

  enum : int { e = X().operator int() };

Also, isn't just about C++11 enums, eg, this should be also accepted:

  enum { e = X() };


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (10 preceding siblings ...)
  2014-08-06 19:46 ` paolo.carlini at oracle dot com
@ 2014-08-07  0:02 ` paolo.carlini at oracle dot com
  2014-08-07 19:52 ` paolo at gcc dot gnu.org
  2014-08-07 19:53 ` paolo.carlini at oracle dot com
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-08-07  0:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Paolo Carlini <paolo.carlini at oracle dot com> ---
build_expr_type_conversion is the answer


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (11 preceding siblings ...)
  2014-08-07  0:02 ` paolo.carlini at oracle dot com
@ 2014-08-07 19:52 ` paolo at gcc dot gnu.org
  2014-08-07 19:53 ` paolo.carlini at oracle dot com
  13 siblings, 0 replies; 15+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-08-07 19:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Thu Aug  7 19:51:28 2014
New Revision: 213736

URL: https://gcc.gnu.org/viewcvs?rev=213736&root=gcc&view=rev
Log:
/cp
2014-08-07  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51312
    * decl.c (build_enumerator): Handle class types with conversion
    operators via perform_implicit_conversion_flags and
    build_expr_type_conversion.

    * cvt.c (build_expr_type_conversion): Replace pair of errors
    with error + inform.

/testsuite
2014-08-07  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51312
    * g++.dg/cpp0x/enum29.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/enum29.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cvt.c
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers)
  2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
                   ` (12 preceding siblings ...)
  2014-08-07 19:52 ` paolo at gcc dot gnu.org
@ 2014-08-07 19:53 ` paolo.carlini at oracle dot com
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-08-07 19:53 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.10.0

--- Comment #14 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed.


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

end of thread, other threads:[~2014-08-07 19:53 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-26 15:16 [Bug c++/51312] New: Wrong interpretation of converted constant expressions (for template arguments and enumerator initializers) tsoae at mail dot ru
2011-11-26 15:33 ` [Bug c++/51312] " marc.glisse at normalesup dot org
2011-11-26 17:32 ` tsoae at mail dot ru
2012-01-30 22:15 ` [Bug c++/51312] [C++0x] Wrong interpretation of converted constant expressions (for " pinskia at gcc dot gnu.org
2012-02-08 20:20 ` pinskia at gcc dot gnu.org
2012-04-29 14:12 ` marc.glisse at normalesup dot org
2014-07-12 19:57 ` paolo.carlini at oracle dot com
2014-07-13  8:54 ` paolo.carlini at oracle dot com
2014-07-13  9:17 ` paolo.carlini at oracle dot com
2014-07-22 10:01 ` glisse at gcc dot gnu.org
2014-07-31 13:26 ` paolo.carlini at oracle dot com
2014-08-06 19:46 ` paolo.carlini at oracle dot com
2014-08-07  0:02 ` paolo.carlini at oracle dot com
2014-08-07 19:52 ` paolo at gcc dot gnu.org
2014-08-07 19:53 ` paolo.carlini at oracle dot com

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).