public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111647] New: g++ accepts different c++ on -fchecking= anf checking=2
@ 2023-09-30 12:32 slyfox at gcc dot gnu.org
  2023-09-30 19:23 ` [Bug c++/111647] " slyfox at gcc dot gnu.org
  2023-10-02 20:19 ` ppalka at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: slyfox at gcc dot gnu.org @ 2023-09-30 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111647
           Summary: g++ accepts different c++ on -fchecking= anf
                    checking=2
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

Encountered when was reducing PR111642 where `make bootstrap4` fails. Reduced
example:

// $ cat rtl-tests.cc.cc
struct poly_int {
  template <typename...> constexpr poly_int() : poly_int() {}
};
template <int> void run() { poly_int(); }

Here is the mismatch between -fchecking=0 and -fchecking=2:

$ /tmp/gb/./prev-gcc/xg++ -B/tmp/gb/./prev-gcc/ -c rtl-tests.cc.cc -o bug
-fchecking=0
$ /tmp/gb/./prev-gcc/xg++ -B/tmp/gb/./prev-gcc/ -c rtl-tests.cc.cc -o bug
-fchecking=2
rtl-tests.cc.cc: In instantiation of ‘constexpr poly_int::poly_int() [with
<template-parameter-1-1> = {}]’:
rtl-tests.cc.cc:4:39:   required from here
rtl-tests.cc.cc:2:58: error: constructor delegates to itself
    2 |   template <typename...> constexpr poly_int() : poly_int() {}
      |          

I think it's an invalid code (clang rejects it as well), but I'm not sure.
AFAIU all -fchecking= options should handle it identically.

gcc is from r14-4339-geaa41a6dc127d8

$ /tmp/gb/./prev-gcc/xg++ -B/tmp/gb/./prev-gcc/ -v
Reading specs from /tmp/gb/./prev-gcc/specs
COLLECT_GCC=/tmp/gb/./prev-gcc/xg++
COLLECT_LTO_WRAPPER=/tmp/gb/./prev-gcc/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib
--enable-languages=c,c++ CC='gcc -O1 -g0' CXX='g++ -O1 -g0'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230929 (experimental) (GCC)

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

* [Bug c++/111647] g++ accepts different c++ on -fchecking= anf checking=2
  2023-09-30 12:32 [Bug c++/111647] New: g++ accepts different c++ on -fchecking= anf checking=2 slyfox at gcc dot gnu.org
@ 2023-09-30 19:23 ` slyfox at gcc dot gnu.org
  2023-10-02 20:19 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: slyfox at gcc dot gnu.org @ 2023-09-30 19:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
More realistic example extracted from gcc's poly_int:

// $ cat rtl-tests.cc
template<unsigned int N> struct poly_int {
  template<typename ...Cs> constexpr poly_int (const Cs &... cs)
  : coeffs { cs... } {}

  int coeffs[N];
};

#define TARGET_DEFINED_VALUE 1
// this works:
//#define TARGET_DEFINED_VALUE 2

// Is instantiated only for N == 2.
template<unsigned int N> struct const_poly_int_tests {
  static void run () {
    poly_int<TARGET_DEFINED_VALUE> (1, 1);
  }
};

$ g++ -c rtl-tests.cc -fchecking=1
# did not fail, BAD!

$ g++ -c rtl-tests.cc -fchecking=2
rtl-tests.cc: In instantiation of 'constexpr poly_int<N>::poly_int(const Cs&
...) [with Cs = {int, int}; unsigned int N = 1]':
rtl-tests.cc:15:42:   required from here
rtl-tests.cc:3:5: error: too many initializers for 'int [1]'
    3 |   : coeffs { cs... } {}
      |     ^~~~~~~~~~~~~~~~
# failed, GOOD

$ clang++ -c rtl-tests.cc
rtl-tests.cc:3:14: error: excess elements in array initializer
  : coeffs { cs... } {}
             ^~
rtl-tests.cc:15:5: note: in instantiation of function template specialization
'poly_int<1>::poly_int<int, int>' requested here
    poly_int<TARGET_DEFINED_VALUE> (1, 1);
    ^
1 error generated.
# failed, GOOD

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

* [Bug c++/111647] g++ accepts different c++ on -fchecking= anf checking=2
  2023-09-30 12:32 [Bug c++/111647] New: g++ accepts different c++ on -fchecking= anf checking=2 slyfox at gcc dot gnu.org
  2023-09-30 19:23 ` [Bug c++/111647] " slyfox at gcc dot gnu.org
@ 2023-10-02 20:19 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-10-02 20:19 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-10-02
     Ever confirmed|0                           |1

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
We probably want to diagnose this regardless of -fchecking.

Here's a similar IFNDR example that we don't diagnose even with -fchecking=2.

struct A { };

void g(A);

template<class T>
void f() {
  g(A(42));
}

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

end of thread, other threads:[~2023-10-02 20:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-30 12:32 [Bug c++/111647] New: g++ accepts different c++ on -fchecking= anf checking=2 slyfox at gcc dot gnu.org
2023-09-30 19:23 ` [Bug c++/111647] " slyfox at gcc dot gnu.org
2023-10-02 20:19 ` ppalka at gcc dot gnu.org

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