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

            Bug ID: 84358
           Summary: error message (missing call to class contructor):
                    misleading source code location
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marco.morandini at polimi dot it
  Target Milestone: ---

Consider the following (wrong) code:
//////////////////////////////
class A {
public:
        A(int i) {};
        A& operator=(const A&) = delete;
        A(const A&) = delete;                                                   
};                                                                              

class B {                                                                       
private:                                                                        
        A a;                                                                    
        const int b;                                                            
public:                                                                         
        B() : b(1) {};                                                          
};                                                                              
//////////////////////////////

The error message is
------------------------------------
marco@pao:~> g++ pippo.C 
pippo.C: In constructor ‘B::B()’:
pippo.C:13:11: error: no matching function for call to ‘A::A()’
  B() : b(1) {};
           ^
pippo.C:3:2: note: candidate: A::A(int)
  A(int i) {};
  ^
pippo.C:3:2: note:   candidate expects 1 argument, 0 provided
------------------------------------

I think that the indication of b(1) as the location of the error, together with
the above message ("no matching function for call to ‘A::A()’": which call?
there is not such call at the offending line!) is misleading. For a complex
code with many members stored inside B it's not obvious that the compiler is
trying to insert a call to A's  constructor.

Reply via email to