public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: Lew Robin <yuejiancao2015@outlook.com>
Cc: "gcc-bugs@gcc.gnu.org" <gcc-bugs@gcc.gnu.org>
Subject: Re: Strange compile error when g++ work with std=c++20.
Date: Mon, 27 Nov 2023 20:33:25 -0800	[thread overview]
Message-ID: <CA+=Sn1kek_YcrSO0Nf=iCmSm2S_zNbjcWajvGENg=pk_b9-PJQ@mail.gmail.com> (raw)
In-Reply-To: <SY4P282MB2348952ACB9CAF30CA751745D2BCA@SY4P282MB2348.AUSP282.PROD.OUTLOOK.COM>

On Mon, Nov 27, 2023 at 8:24 PM Lew Robin via Gcc-bugs
<gcc-bugs@gcc.gnu.org> wrote:
>
> This error happens when using macro and template.
> GCC Version: gcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~22.04)
> OS: ubuntu 22.04 (x64)
> Compile Command:
> g++-12 ./testmacro.cc --std=c++20
>
> In fact, this error exisits from g++11 to g++13.  I also test it on clang and msvc, but it cannot be reproduced.

GCC is correct here.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103593 which points
to C++20 DR 2237 (and the bug about diagnostic that should be improved
is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97202).
I suspect clang and MSVC has not implemented that C++ defect report
which is why it is accepted by those 2.

Thanks,
Andrew Pinski


>
> short reproduction:
> #include <mutex>
>
> #define DECLARE_SINGLETON(classname_type)     \
>   public:                                     \
>   classname_type();
>
> template <class MessageT>
> class ReceiverManager
> {
> public:
>   ~ReceiverManager() { }
>
> private:
>   MessageT receiver_map_;
>   DECLARE_SINGLETON(ReceiverManager<MessageT>)
> };
>
> template <typename MessageT>
> ReceiverManager<MessageT>::ReceiverManager(){}
>
> int main()
> {
>   auto m = ReceiverManager<int>();
>   return 0;
> }
> compile it and report error:
>
> ./testmacro.cc:5:24: error: expected unqualified-id before ‘)’ token
>     5 |         classname_type();
>       |                        ^
> ./testmacro.cc:15:9: note: in expansion of macro ‘DECLARE_SINGLETON’
>    15 |         DECLARE_SINGLETON(ReceiverManager<MessageT>)
>       |         ^~~~~~~~~~~~~~~~~
> ./testmacro.cc:19:1: error: no declaration matches ‘ReceiverManager<MessageT>::ReceiverManager()’
>    19 | ReceiverManager<MessageT>::ReceiverManager(){}
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~
> ./testmacro.cc:19:1: note: no functions named ‘ReceiverManager<MessageT>::ReceiverManager()’
> ./testmacro.cc:8:7: note: ‘class ReceiverManager<MessageT>’ defined here
>     8 | class ReceiverManager
>       |       ^~~~~~~~~~~~~~~

  reply	other threads:[~2023-11-28  4:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28  4:24 Lew Robin
2023-11-28  4:33 ` Andrew Pinski [this message]
2023-11-28  9:25 ` Jonathan Wakely

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='CA+=Sn1kek_YcrSO0Nf=iCmSm2S_zNbjcWajvGENg=pk_b9-PJQ@mail.gmail.com' \
    --to=pinskia@gmail.com \
    --cc=gcc-bugs@gcc.gnu.org \
    --cc=yuejiancao2015@outlook.com \
    /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).