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

            Bug ID: 94024
           Summary: Error message has misleading source location for
                    constructor member initialisation.
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cubitect at gmail dot com
  Target Milestone: ---

The error messages resulting from some types of incorrect initialisation,
within a constructor's initialisation list, indicate the error location to be
at the last member initialisation rather than the affected member. According to
godbolt all version of g++ have this behaviour.

/// test code:
struct A {
    A() 
    : a()       // erroneous value-initialization of reference
    , b(1i)     // erroneous complex conversion 
    , c('a')    // errors are incorrectly displayed at member c
    {}

    int &a;
    int b;
    char c;
};

/// <source>: In constructor 'A::A()':
/// <source>:5:12: error: value-initialization of reference type 'int&'
///     5 |     , c('a')    // errors are incorrectly displayed at member c
///       |            ^
/// <source>:5:12: error: cannot convert '__complex__ int' to 'int' in
initialization

Reply via email to