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

            Bug ID: 127249
           Summary: Wrong caret location for invalid mem-initializer
           Product: gcc
           Version: 15.3.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

template<typename T, typename... U>
struct Foo : T
{
  int inner;

  Foo() : T(), inner() { }
};

struct NoDefault { NoDefault(int) { } };

int main()
{
  Foo<NoDefault> f;
}

This code is ill-formed, but the location is unhelpful:

def.cc: In instantiation of 'Foo<T, U>::Foo() [with T = NoDefault; U = {}]':
def.cc:13:18:   required from here
   13 |   Foo<NoDefault> f;
      |                  ^
def.cc:6:22: error: no matching function for call to 'NoDefault::NoDefault()'
    6 |   Foo() : T(), inner() { }
      |                      ^
  * there are 3 candidates
    * candidate 1: 'NoDefault::NoDefault(int)'
      def.cc:9:20:
          9 | struct NoDefault { NoDefault(int) { } };
            |                    ^~~~~~~~~
      * candidate expects 1 argument, 0 provided
    * candidate 2: 'constexpr NoDefault::NoDefault(const NoDefault&)'
      def.cc:9:8:
          9 | struct NoDefault { NoDefault(int) { } };
            |        ^~~~~~~~~
      * candidate expects 1 argument, 0 provided
    * candidate 3: 'constexpr NoDefault::NoDefault(NoDefault&&)'
      * candidate expects 1 argument, 0 provided


The error line points to inner() but the problem is T(). This is quite
confusing in a complicated template where there are lots of types involved.

Reply via email to