public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/61638] "warning: multi-line comment" unclear and has false positives
       [not found] <bug-61638-4@http.gcc.gnu.org/bugzilla/>
@ 2023-02-06  6:14 ` adrianh.bsc at gmail dot com
  2023-02-06  6:24 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: adrianh.bsc at gmail dot com @ 2023-02-06  6:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61638

Jack Adrian Zappa <adrianh.bsc at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |adrianh.bsc at gmail dot com

--- Comment #9 from Jack Adrian Zappa <adrianh.bsc at gmail dot com> ---
Issue:
  Cannot turn off the `-Wcomment` option using `#pragma GCC diagnostic ignored
  "-Wcomment"`.  This is causing issues when I'm trying to document my macros
  and how to write them.  Our coding standards at my work state that we are to
  use /// for documenting functions/variables/macros and not /** */.

  I grudgingly tried to use a space after the \, but that didn't work either.
  Also inadvertently found that ending with a double backslash (\\) also didn't
  work for some reason, which is odd because the backslash is escaped, so it
  cannot cause a comment continuation.

  Suggest fix is to either:

  1. Change the phase where this warning/error/ignored is tested so that the
     #pragma GCC diagnostic is honoured or

  2. If a line comment end in an \ but the next line is a comment, then do
     the same thing as is done for a multi-line comment, ignore it as not an
     issue.

  In addition, a line comment ending in an escaped backslash shouldn't cause
  any issue.  It would be also preferable that an escaped whitespace that is
  not an eol character would be accepted (though it seems that this is unlikely
  given bug 8270).

GCC versions tested on:
  7.5, 11.3 12.2

System type:
  MSYS2 and whatever is running under godbolt.org

Options given:
  -Wall -Werror

Complete command line:
  g++ -Wall -Werror bug.cpp

Source file:
$ cat bug.cpp
  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wcomment"
  /// #define macro_to_document(x) \
  ///   blah blah x blah
  ///
  /// Also doesn't work with a space after the \
  /// as in this case.
  ///
  /// Also doesn't work with a double backslash \\
  /// as in this case.
  ///
  #pragma GCC diagnostic pop

Compiler output:
$  g++ -v -Wall -Werror -save-temps bug.cpp
  Using built-in specs.
  COLLECT_GCC=g++
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/11.3.0/lto-wrapper.exe
  Target: x86_64-pc-msys
  Configured with: /c/S/gcc/src/gcc-11.3.0/configure --build=x86_64-pc-msys
--prefix=/usr --libexecdir=/usr/lib --enable-bootstrap --enable-shared
--enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs
--with-arch=x86-64 --with-tune=generic --disable-multilib --enable-__cxa_atexit
--with-dwarf2 --enable-languages=c,c++,fortran,lto --enable-graphite
--enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm
--enable-libquadmath --enable-libquadmath-support --disable-libssp
--disable-win32-registry --disable-symvers --with-gnu-ld --with-gnu-as
--disable-isl-version-check --enable-checking=release --without-libiconv-prefix
--without-libintl-prefix --with-system-zlib --enable-linker-build-id
--with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
  Thread model: posix
  Supported LTO compression algorithms: zlib
  gcc version 11.3.0 (GCC)
  COLLECT_GCC_OPTIONS='-v' '-Wall' '-Werror' '-save-temps' '-shared-libgcc'
'-mtune=generic' '-march=x86-64' '-dumpdir' 'a-'
   /usr/lib/gcc/x86_64-pc-msys/11.3.0/cc1plus.exe -E -quiet -v -idirafter
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../lib/../include/w32api -idirafter
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api
bug.cpp -mtune=generic -march=x86-64 -Wall -Werror -fpch-preprocess -o a-bug.ii
  ignoring nonexistent directory "/usr/local/include"
  ignoring nonexistent directory
"/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/include"
  ignoring duplicate directory
"/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api"
  #include "..." search starts here:
  #include <...> search starts here:
   /usr/lib/gcc/x86_64-pc-msys/11.3.0/include/c++
   /usr/lib/gcc/x86_64-pc-msys/11.3.0/include/c++/x86_64-pc-msys
   /usr/lib/gcc/x86_64-pc-msys/11.3.0/include/c++/backward
   /usr/lib/gcc/x86_64-pc-msys/11.3.0/include
   /usr/lib/gcc/x86_64-pc-msys/11.3.0/include-fixed
   /usr/include
   /usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../lib/../include/w32api
  End of search list.
  bug.cpp:3:1: error: multi-line comment [-Werror=comment]
      3 | /// #define macro_to_document(x) \
        | ^
  bug.cpp:6:1: error: multi-line comment [-Werror=comment]
      6 | /// Also doesn't work with a space after the \
        | ^
  bug.cpp:9:1: error: multi-line comment [-Werror=comment]
      9 | /// Also doesn't work with a double backslash \\
        | ^
  cc1plus: all warnings being treated as errors

Preprocessed file:
  $ cat a-bug.ii
  # 0 "bug.cpp"
  # 0 "<built-in>"
  # 0 "<command-line>"
  # 1 "bug.cpp"
  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wcomment"
  # 12 "bug.cpp"
  #pragma GCC diagnostic pop

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug preprocessor/61638] "warning: multi-line comment" unclear and has false positives
       [not found] <bug-61638-4@http.gcc.gnu.org/bugzilla/>
  2023-02-06  6:14 ` [Bug preprocessor/61638] "warning: multi-line comment" unclear and has false positives adrianh.bsc at gmail dot com
@ 2023-02-06  6:24 ` pinskia at gcc dot gnu.org
  2023-02-07  3:14 ` adrianh.bsc at gmail dot com
  2023-02-07  3:17 ` LpSolit at gmail dot com
  3 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-06  6:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61638

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jack Adrian Zappa from comment #9)

>   
>   Suggest fix is to either:
>   
>   1. Change the phase where this warning/error/ignored is tested so that the
>      #pragma GCC diagnostic is honoured or

That is fixed on the trunk for GCC 13 (by r13-1544-ge46f4d7430c52104657916) for
the C++ front-end, it was already working for the C front-end.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug preprocessor/61638] "warning: multi-line comment" unclear and has false positives
       [not found] <bug-61638-4@http.gcc.gnu.org/bugzilla/>
  2023-02-06  6:14 ` [Bug preprocessor/61638] "warning: multi-line comment" unclear and has false positives adrianh.bsc at gmail dot com
  2023-02-06  6:24 ` pinskia at gcc dot gnu.org
@ 2023-02-07  3:14 ` adrianh.bsc at gmail dot com
  2023-02-07  3:17 ` LpSolit at gmail dot com
  3 siblings, 0 replies; 4+ messages in thread
From: adrianh.bsc at gmail dot com @ 2023-02-07  3:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61638

--- Comment #11 from Jack Adrian Zappa <adrianh.bsc at gmail dot com> ---
That's great.  Too bad I'm stuck on 7.5. :D :'(

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug preprocessor/61638] "warning: multi-line comment" unclear and has false positives
       [not found] <bug-61638-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2023-02-07  3:14 ` adrianh.bsc at gmail dot com
@ 2023-02-07  3:17 ` LpSolit at gmail dot com
  3 siblings, 0 replies; 4+ messages in thread
From: LpSolit at gmail dot com @ 2023-02-07  3:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61638

--- Comment #12 from Jack Adrian Zappa <adrianh.bsc at gmail dot com> ---
Is it possible that 

  2. If a line comment end in an \ but the next line is a comment, then do
     the same thing as is done for a multi-line comment, ignore it as not an
     issue.

Could be done. I know I said or, but it would be nice not to have to add a
pragma if it is not necessary.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-14 21:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-61638-4@http.gcc.gnu.org/bugzilla/>
2023-02-06  6:14 ` [Bug preprocessor/61638] "warning: multi-line comment" unclear and has false positives adrianh.bsc at gmail dot com
2023-02-06  6:24 ` pinskia at gcc dot gnu.org
2023-02-07  3:14 ` adrianh.bsc at gmail dot com
2023-02-07  3:17 ` LpSolit at gmail dot com

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