Gcc TemplateClass <:: GlobalSymbol> error when <::

For some reason, gcc doesn't like it when the template parameter is a global namespace symbol, i.e.

 TemplateClass<::GlobalSymbol> 

It works when I do

 TemplateClass< ::GlobalSymbol> 

That is, gcc does not like to see <::

Is it possible to prevent without changing the sources (which are generated automatically)?

UPD: I do not want to change the sources. I found that -fpermissive seems to change this to a warning instead of an error, but have not yet found how to include it from code (e.g. using pragmas).

UPD: I found that

  #pragma GCC diagnostic ignored "-fpermissive" 

does the trick, anyway I accept the answer that helped me figure this out.

+4
source share
2 answers

<: is a digraph , which is equivalent to [ , therefore, an error. Since you don't want to change the code, a workaround is to use the -fpermissive command line -fpermissive or pragma for g ++ (this really gives you a hint):

 test.cpp:9:16: note: (if you use '-fpermissive' G++ will accept your code) 
+8
source

With gcc 4.6, I get the following error:

 graphs.cpp: In function 'int main()': graphs.cpp:9:15: error: '<::' cannot begin a template-argument list [-fpermissive] graphs.cpp:9:15: note: '<:' is an alternate spelling for '['. Insert whitespace between '<' and '::' graphs.cpp:9:15: note: (if you use '-fpermissive' G++ will accept your code) 

So, -permission is the way to go. [EDIT: now I see that you added that you already found this]

Otherwise, since you mentioned that the sources were generated automatically, you can add a post-processing step. For example, using sed

 sed -i 's,<::,< ::,g' filename.cpp 

or something like that, for example. python. But only if you are sure that you never use <:: for anything else.

0
source

Source: https://habr.com/ru/post/1394616/


All Articles