Bug 79398 - misleading error static constexpr member function called in a constant expression before its definition is complete
Summary: misleading error static constexpr member function called in a constant expres...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2017-02-06 22:28 UTC by Martin Sebor
Modified: 2023-11-13 22:42 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2017-02-06 22:28:38 UTC
The error below is a bit confusing: the definition of B::bar() is complete when it's called.

I think I understand that the reason for the error below is actually that the function is called before the definition of the class of which it's a member is complete.  The error should make that clear, although it seems that accepting it (e.g., as an extension) would make static constexpr member functions quite a bit more useful.

$ cat y.C && gcc -S -Wall -Wextra -Wpedantic y.C 
struct A {
  static constexpr int foo () { return 1; }
};

struct B: A {
  static constexpr int bar () { return 2; }
  enum E { e = B::foo () };
  enum F { f = B::bar () };
};
y.C:8:23: error: ‘static constexpr int B::bar()’ called in a constant expression before its definition is complete
   enum F { f = B::bar () };
                ~~~~~~~^~
y.C:8:24: error: enumerator value for ‘f’ is not an integer constant
   enum F { f = B::bar () };
                        ^
Comment 1 Eric Gallager 2017-08-29 01:10:39 UTC
(In reply to Martin Sebor from comment #0)
> The error below is a bit confusing: the definition of B::bar() is complete
> when it's called.
> 
> I think I understand that the reason for the error below is actually that
> the function is called before the definition of the class of which it's a
> member is complete.  The error should make that clear, although it seems
> that accepting it (e.g., as an extension) would make static constexpr member
> functions quite a bit more useful.

Confirmed. If accepting it as an extension, sounds like material for -fpermissive.
Comment 2 Eric Gallager 2018-11-06 03:08:04 UTC
(In reply to Eric Gallager from comment #1)
> (In reply to Martin Sebor from comment #0)
> > The error below is a bit confusing: the definition of B::bar() is complete
> > when it's called.
> > 
> > I think I understand that the reason for the error below is actually that
> > the function is called before the definition of the class of which it's a
> > member is complete.  The error should make that clear, although it seems
> > that accepting it (e.g., as an extension) would make static constexpr member
> > functions quite a bit more useful.
> 
> Confirmed. If accepting it as an extension, sounds like material for
> -fpermissive.

C++ FE maintainers, is this something you'd want to do?