Strange compile error when g++ work with std=c++20.
Andrew Pinski
pinskia@gmail.com
Tue Nov 28 04:33:25 GMT 2023
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
> | ^~~~~~~~~~~~~~~
More information about the Gcc-bugs
mailing list