public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52282] New: [C++0x] ICE / confused by earlier errors with decltype/constexpr
@ 2012-02-16 15:56 andyg1001 at hotmail dot co.uk
  2012-02-16 19:41 ` [Bug c++/52282] " daniel.kruegler at googlemail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: andyg1001 at hotmail dot co.uk @ 2012-02-16 15:56 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52282
           Summary: [C++0x] ICE / confused by earlier errors with
                    decltype/constexpr
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: andyg1001@hotmail.co.uk


The following code causes the compiler problems.  The version I am using is gcc
4.7.0-20120210.


template <typename T, T V>
struct A
    {
    static constexpr T a() { return V; }
    };

template <typename T, T V>
struct B
    {
    typedef T type;
    static constexpr type b() { return V; }
    };

template <typename T, T V>
struct C
    {
    static constexpr decltype(V) c() { return V; }
    };

static_assert(A<int, 10>::a() == 10, "oops");
static_assert(B<int, 10>::b() == 10, "oops");
static_assert(C<int, 10>::c() == 10, "oops");

struct D
    {
    static constexpr int d() { return 10; }
    };

static_assert((A<int(*)(), &D::d>::a())() == 10, "oops");
static_assert((B<int(*)(), &D::d>::b())() == 10, "oops"); // line 30
static_assert((C<int(*)(), &D::d>::c())() == 10, "oops");


The code as given above will give the following output:

1.cpp:30:1: error: non-constant condition for static assertion
1.cpp:30:38: error: expression ‘D::d’ does not designate a constexpr function
1.cpp:17: confused by earlier errors, bailing out

Commenting out the line 30 will produce an ICE instead:

1.cpp: In instantiation of ‘struct C<int (*)(), D::d>’:
1.cpp:31:34:   required from here
1.cpp:17:31: internal compiler error: in finish_decltype_type, at
cp/semantics.c:5277

There are two issues here: the first is, of course, the ICE; the second is that
gcc is not correctly determining the return type when it is abstracted as in
structs B and C and the type is a static function pointer.

Note that non-static member function pointers do not generate either issues,
although it is necessary to add "const" to the pointer type but not to the
corresponding function definition:

struct E
    {
    constexpr int e() { return 10; }
    };

constexpr E e;
static_assert((e.*A<int(E::*)()const, &E::e>::a())() == 10, "oops");
static_assert((e.*B<int(E::*)()const, &E::e>::b())() == 10, "oops");
static_assert((e.*C<int(E::*)()const, &E::e>::c())() == 10, "oops");


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

end of thread, other threads:[~2014-11-17 19:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-16 15:56 [Bug c++/52282] New: [C++0x] ICE / confused by earlier errors with decltype/constexpr andyg1001 at hotmail dot co.uk
2012-02-16 19:41 ` [Bug c++/52282] " daniel.kruegler at googlemail dot com
2012-02-24 18:33 ` andyg1001 at hotmail dot co.uk
2012-05-04 16:22 ` andyg1001 at hotmail dot co.uk
2012-05-04 16:43 ` daniel.kruegler at googlemail dot com
2012-05-04 18:41 ` paolo.carlini at oracle dot com
2012-05-07 10:07 ` paolo.carlini at oracle dot com
2013-05-01 11:48 ` paolo.carlini at oracle dot com
2014-11-17 17:01 ` [Bug c++/52282] [C++0x] rejects-valid issues " jason at gcc dot gnu.org
2014-11-17 19:19 ` jason 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).