public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Strange compile error when g++ work with std=c++20.
@ 2023-11-28 4:24 Lew Robin
2023-11-28 4:33 ` Andrew Pinski
2023-11-28 9:25 ` Jonathan Wakely
0 siblings, 2 replies; 3+ messages in thread
From: Lew Robin @ 2023-11-28 4:24 UTC (permalink / raw)
To: gcc-bugs
[-- Attachment #1.1: Type: text/plain, Size: 1568 bytes --]
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.
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
| ^~~~~~~~~~~~~~~
[-- Attachment #2: testmacro.cc --]
[-- Type: application/octet-stream, Size: 440 bytes --]
#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;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Strange compile error when g++ work with std=c++20.
2023-11-28 4:24 Strange compile error when g++ work with std=c++20 Lew Robin
@ 2023-11-28 4:33 ` Andrew Pinski
2023-11-28 9:25 ` Jonathan Wakely
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Pinski @ 2023-11-28 4:33 UTC (permalink / raw)
To: Lew Robin; +Cc: gcc-bugs
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
> | ^~~~~~~~~~~~~~~
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Strange compile error when g++ work with std=c++20.
2023-11-28 4:24 Strange compile error when g++ work with std=c++20 Lew Robin
2023-11-28 4:33 ` Andrew Pinski
@ 2023-11-28 9:25 ` Jonathan Wakely
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2023-11-28 9:25 UTC (permalink / raw)
To: yuejiancao2015; +Cc: gcc-bugs
This mailing list is for automated email from our Bugzilla bug
database, not for reporting bugs directly.
Please see https://gcc.gnu.org/bugs/ for instructions on how to report
bugs.
However, Andrew already explained why GCC is correct and this is not a
GCC bug. Just use DECLARE_SINGLETON(ReceiverManager) to fix your code.
The constructor should be declared as ReceiverManager() just like your
destructor is declared as ~ReceiverManager(), not as
~ReceiverManager<MessageT>().
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-28 9:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 4:24 Strange compile error when g++ work with std=c++20 Lew Robin
2023-11-28 4:33 ` Andrew Pinski
2023-11-28 9:25 ` Jonathan Wakely
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).