danielappiagyei-bc commented on issue #10556:
URL: https://github.com/apache/nuttx/issues/10556#issuecomment-1712717696

   > I include 
[segger/rtt.h](https://github.com/apache/nuttx/blob/nuttx-12.2.1/include/nuttx/segger/rtt.h)
 in a file of mine that gets compiled as C++ but compilation fails due to rtt.h 
using the C++ reserved keyword public for fields in struct lib_rttoutstream_s 
and struct lib_rttinstream_s. Additionally, the transitive include 
[streams.h](https://github.com/apache/nuttx/blob/nuttx-12.2.1/include/nuttx/streams.h)
 uses public as well as the this keyword (e.g., 
[here](https://github.com/apache/nuttx/blob/nuttx-12.2.1/include/nuttx/streams.h#L73)
 and 
[here](https://github.com/apache/nuttx/blob/nuttx-12.2.1/include/nuttx/streams.h#L140)).
   
   
   Following up, GCC has the 
[-Wc++-compat](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wc_002b_002b-compat)
 warning which can catch this in the future. Below is an excerpt of what it 
found from the code snippet in my previous comment. I also added the following 
line to see if it would catch the `this` keyword: `int this = 0;`
   
   ```
   gpio.c:136:9: warning: identifier 'this' conflicts with C++ keyword 
[-Wc++-compat]
     136 |     int this = 0;
         |         ^~~~
   gpio.c:142:16: warning: identifier 'public' conflicts with C++ keyword 
[-Wc++-compat]
     142 |     out_stream.public.putc(&out_stream.public, (int)'d');
         |                ^~~~~~
   gpio.c:142:40: warning: identifier 'public' conflicts with C++ keyword 
[-Wc++-compat]
     142 |     out_stream.public.putc(&out_stream.public, (int)'d');
         |                                        ^~~~~~
   ```
   
   If enabling this check across all of nuttx would be too restrictive (because 
of other, unwanted things it warns about) then an alternative would be a 
shellscript which compiles nuttx with this warning enabled and greps the output 
for "conflicts with C++ keyword". If found then the script would exit 
unsuccessfully. This could be a companion to `nxstyle`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to