public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "robinh3123 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/67113] New: unintelligent error message "only declarations of constructors can be 'explicit'" in cpp file's constructor define.
Date: Tue, 04 Aug 2015 10:43:00 -0000	[thread overview]
Message-ID: <bug-67113-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 67113
           Summary: unintelligent error message "only declarations of
                    constructors can be 'explicit'" in cpp file's
                    constructor define.
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: robinh3123 at gmail dot com
  Target Milestone: ---

For the following codes (in 3 files):

$ cat a.cpp
#include "a.h"

int A::f()
{
        return n+1;
}

explicit A::A(int _n)   // <=== error at this line
{
        n = _n;
}



$ cat  a.h
class A
{
public:
        int n;
        int f();
        explicit A(int _n);
};



$ cat main.cpp
#include <iostream>
#include "a.h"  // for class A

using namespace std;

int main()
{
        A a(5);
        int i = a.f();
        cout << i << endl;
    return 0;
}


The compiler reports error message:
a.cpp:8:21: error: only declarations of constructors can be 'explicit'
 explicit A::A(int _n)

This is misleading, since A::A is really a constructor.
The error message should be something similar to:
     extra explicit before function A::A


             reply	other threads:[~2015-08-04 10:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-04 10:43 robinh3123 at gmail dot com [this message]
2015-08-04 11:47 ` [Bug c++/67113] " redi at gcc dot gnu.org
2015-08-04 11:50 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-67113-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).