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

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).