[Bug c/29129] [4.2/4.3/4.4 Regression] [DR#341] unnamed parameters using [*]

2023-04-06 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29129

zhonghao at pku dot org.cn changed:

   What|Removed |Added

 CC||zhonghao at pku dot org.cn

--- Comment #13 from zhonghao at pku dot org.cn ---
I tried the latest gcc, but it rejects the sample code:
:1:23: error: expected primary-expression before ']' token
1 | void f(unsigned int [*]);
  |   ^
Compiler returned: 1

Is this a regression? Or, the idea is changed, and this code shall be rejected?

[Bug c/64480] List designated initializer triggers -Wmissing-field-initializers

2023-04-06 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64480

zhonghao at pku dot org.cn changed:

   What|Removed |Added

 CC||zhonghao at pku dot org.cn

--- Comment #4 from zhonghao at pku dot org.cn ---
Is this bug fixed? I tried the latest gcc, but it still rejects the sample
code.

[Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86

2023-04-06 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63495

zhonghao at pku dot org.cn changed:

   What|Removed |Added

 CC||zhonghao at pku dot org.cn

--- Comment #7 from zhonghao at pku dot org.cn ---
I tried to compile the sample code with the latest gcc.

struct __attribute__ ((aligned (8))) s { char c; };
_Static_assert (_Alignof (struct s) >= 8, "wrong alignment");

However, it does not compile. Is this a regression?

[Bug c/85696] OpenMP with variably modified and default(none) won't compile

2023-04-05 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85696

zhonghao at pku dot org.cn changed:

   What|Removed |Added

 CC||zhonghao at pku dot org.cn

--- Comment #11 from zhonghao at pku dot org.cn ---
Is this bug really fixed? I tried the latest version, but it is still rejected:

:1:28: error: use of parameter outside function body before ']' token
1 |   void foo(int n, int a[][n])
  |^
: In function 'void foo(...)':
:4:9: error: 'a' was not declared in this scope
4 | a[23][0] = 42;
  | ^
Compiler returned: 1

[Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates

2023-04-05 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426

Bug ID: 109426
   Summary: Gcc runs into Infinite loop, when resolving templates
   Product: gcc
   Version: 12.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

typedef struct astruct_d
{
 void *data;
} astruct;

/* Generate a whole bunch of unique fake mallocs, this
 keeps the vartrack dump simpler to understand (all
 the "size" arguments have a unique name). */
#define DE0(X) \
 void *malloc##X (unsigned long size##X);
#define DE1(X) \
 DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \
 DE0(X##5) DE0(X##6) DE0(X##7) DE0(X##8) DE0(X##9)
#define DE2(X) \
 DE1(X##0) DE1(X##1) DE1(X##2) DE1(X##3) DE1(X##4) \
 DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9)
#define DE3(X) \
 DE2(X##0) DE2(X##1) DE2(X##2) DE2(X##3) DE2(X##4) \
 DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9)
#define DE4(X) \
 DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \
 DE3(X##5) DE3(X##6) DE3(X##7) DE3(X##8) DE3(X##9)
DE4(0)
#undef DE0
#undef DE1
#undef DE2
#undef DE3
#undef DE4

void foo (void)
{
/* Now call all those mallocs and generate a series of
 variables while at it. */
#define DE0(X) \
 astruct *A##X = (astruct *) malloc##X(sizeof (astruct));
#define DE1(X) \
 DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \
 DE0(X##5) DE0(X##6) DE0(X##7) DE0(X##8) DE0(X##9)
#define DE2(X) \
 DE1(X##0) DE1(X##1) DE1(X##2) DE1(X##3) DE1(X##4) \
 DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9)
#define DE3(X) \
 DE2(X##0) DE2(X##1) DE2(X##2) DE2(X##3) DE2(X##4) \
 DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9)
#define DE4(X) \
 DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \
 DE3(X##5) DE3(X##6) DE3(X##7) DE3(X##8) DE3(X##9)
DE4(0)
DE4(1)
}

GCC runs into an infinite loop:

code0.c:35:18: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
   35 |  astruct *A##X = (astruct *) malloc##X(sizeof (astruct));
  |  ^
code0.c:37:32: note: in expansion of macro ‘DE0’
   37 |  DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \
  |^~~
code0.c:41:42: note: in expansion of macro ‘DE1’
   41 |  DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9)
  |  ^~~
code0.c:44:2: note: in expansion of macro ‘DE2’
   44 |  DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9)
  |  ^~~
code0.c:46:22: note: in expansion of macro ‘DE3’
   46 |  DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \
  |  ^~~
code0.c:49:1: note: in expansion of macro ‘DE4’
   49 | DE4(1)
  | ^~~

[Bug c++/105997] New: A possible optimization bug

2022-06-16 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105997

Bug ID: 105997
   Summary: A possible optimization bug
   Product: gcc
   Version: 10.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

ZynAddSubFX is a musical synthesizer. I find a strange code in this project:

https://github.com/zynaddsubfx/zynaddsubfx/blob/master/src/Misc/MiddleWare.cpp

#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
#pragma GCC push_options
#pragma GCC optimize("O0")
#endif

void gcc_10_1_0_is_dumb(const std::vector ,
const int N,
char *types,
rtosc_arg_t *args)
{
types[N] = 0;
for(int i=0; ihttps://github.com/zynaddsubfx/zynaddsubfx/commit/a1abae354e826802f8b6f990cae225d6fb06b2ac

"Disable gcc optimizations for a specific function

Due to a gcc opt bug a piece of code was put in a separate function to
prevent gcc from optimizing it. Later versions of gcc inlined the
function and the bug reappeared. So now we explicitly tell gcc to not
optimize it."

Is it real a GCC bug?

[Bug middle-end/105905] A possible rounding error

2022-06-11 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105905

--- Comment #2 from zhonghao at pku dot org.cn ---
A programmer answered me, and provided some details. Here, I copy his response:

"This code:

Vector2 v{Math::sin(37.0_degf), Math::cos(37.0_degf)};

Utility::print("{:.10}\n", v[1]);
Utility::print("{:.10}\n", (v*v.lengthInverted())[1]);
Utility::print("{:.10}\n", (v/v.length())[1]);
prints the following in a debug build (-march=native -g) and in a release build
without -march=native (so just -O3.

0.7986354828
0.7986354828
0.7986354828
However, it prints the following in a -march=native -O3 build.

0.7986354828
0.798635602
0.7986355424
Okay, so I thought it's some optimization kicking in, producing a different
result, but then I realized that this code:

Vector2 v{Math::sin(37.0_degf), Math::cos(37.0_degf)};

// Utility::print("{:.10}\n", v[1]);
Utility::print("{:.10}\n", (v*v.lengthInverted())[1]);
Utility::print("{:.10}\n", (v/v.length())[1]);
prints

0.7986354828
0.7986354828
even with -march=native -O3. So, ummm, the v[1] in combination with
Utility::print() causes that particular optimization to kick in, and if it's
not there, it doesn't optimize anything? If I change Utility::print() to
std::printf(), it also stops being strange and prints 0.7986354828 three times.
So I suppose there has to be sufficiently complex code around these operations
to make some optimization kick in? I tried to look at the disassembly, the
"strange" variant has a bunch of FMA calls, the non-strange variant has none,
but those calls could also have been somewhere else, I'm not that good at
understanding the compiler output.

I tested with GCC 10 as well, and it has the same weird behavior as 11.
Unfortunately I don't remember if I was at GCC 10 or 9 before that commit.
Clang prints 0.7986354828 always.
"

[Bug c++/105905] New: A possible rounding error

2022-06-09 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105905

Bug ID: 105905
   Summary: A possible rounding error
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

magnum is a data visualization library. I notice that its programmers
complained a rounding error in gcc. It occurs when compiling their code in the
release version. To fix the problem, they change their test cases, which is a
workaround:

https://github.com/mosra/magnum/commit/fb51f25a7b613aa5be744deea5a4ddb88f3de064

I also open an issue in magnum. Its programmers can provide more feedback.

[Bug c++/105884] New: A possible optimization bug when uint64_t is used with -O2/-O3.

2022-06-08 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105884

Bug ID: 105884
   Summary: A possible optimization bug when uint64_t is used with
-O2/-O3.
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

zapret is a tool to bypass network blocking:
https://github.com/bol-van/zapret/blob/master/docs/readme.eng.md

I notice that its programmers complain an optimization bug. This bug is
triggered when gcc optimizes uint64_t. The commit is
https://github.com/bol-van/zapret/commit/9402cd2cf0a16352a3401f7bce1a894bf131138b

Please check the problem.

[Bug c++/105882] New: A possible constexpr bug

2022-06-08 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105882

Bug ID: 105882
   Summary: A possible constexpr bug
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code sample is as follows:

#include 

struct real128
{
__float128 m_value;

template 
constexpr bool get(T ) const
{
using value_type = typename T::value_type;

rop.real(static_cast(m_value));
rop.imag(static_cast(0));

return true;
}
};

constexpr auto fappo(real128 x)
{
std::complex ret{1,2};
x.get(ret);
return ret;
}

constexpr auto flap = fappo(real128{4});

gcc rejects this code, but clang accepts it. mp++ is a library for
multiprecision arithmetic. Its programmers disable several code lines, when gcc
compiles this project. Please check:
https://github.com/bluescarni/mppp/commit/628651b9928e35dc09c0c2de3d2561abababb55f

[Bug c++/105881] New: GCC release mode can crash Torque3D

2022-06-08 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105881

Bug ID: 105881
   Summary: GCC release mode can crash Torque3D
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

Torque3D is an open source game engine: https://torque3d.org/
When I read its code, I notice that it fixes a crash, and this crash can be
caused by GCC. 
The bug report is https://github.com/TorqueGameEngines/Torque3D/pull/559

The fix looks simple:
https://github.com/TorqueGameEngines/Torque3D/commit/1b55dce613dab6122aa7660d546328e83b103534


I have sent this bug report to Torque3D programmers. Hope that they can provide
more details of this bug.

[Bug c++/105460] New: sizeof (unsigned int) != sizeof (uint8_t *)

2022-05-03 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105460

Bug ID: 105460
   Summary: sizeof (unsigned int) != sizeof (uint8_t *)
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

Clang's comments say there is an `unsigned int`-sized "reserved" member here,
because when the objc4 modern runtime is used on LP64 platforms, there would
otherwise be a 32-bit-sized hole here for alignment reasons.

However, it doesn't actually add the "reserved" field to its AST data
structures.
GCC *does* add the field explicitly. On LP64, adding it or not is irrelevant. 
But on AVR, sizeof (unsigned int) == sizeof (uint8_t *), and it matters.

An example is
from:https://github.com/mhjacobson/avr-objc/commit/6187e336d706f1a87a7f0cbd9efa838f9d966737

This means that I have to compile Objective-C code either all with clang or all
with GCC.

[Bug c++/105457] New: error: '__builtin_huge_valq()' is not a constant expression

2022-05-02 Thread zhonghao at pku dot org.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105457

Bug ID: 105457
   Summary: error: '__builtin_huge_valq()' is not a constant
expression
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

template 
struct infinity{};

template <> struct infinity<__float128> { static constexpr __float128 value =
__builtin_huge_valq(); };

int main() {
auto x = infinity<__float128>::value;
}

GCC 7.1+ accepts this code, but GCC 6.4 rejects it. I tried clang and other
compilers. They all reject the code:https://godbolt.org/z/qWb5oe4dx

The above code comes from kokkos:

https://github.com/mosra/corrade/commit/59823941093bee9f99e5a63cb4218b53a7bd5495

Look like a gcc bug?

[Bug c++/90925] gcc allows calling private overridden operators

2019-06-19 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90925

--- Comment #2 from zhonghao at pku dot org.cn ---
A related code sample:

class A
{
 virtual int String ();
};

class F: public A { };

template < typename V > class G
{
 private: V value;
};

class D
{
 template < int N > void Verify() {
 G* x = 0;
 F& name = x->value;
 name.String();
 }
};

gcc also accepts it, although x->value is private.

[Bug c++/90925] New: gcc allows calling private overridden operators

2019-06-19 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90925

Bug ID: 90925
   Summary: gcc allows calling private overridden operators
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and my code is:

class a {
 private: template  a <<(b);
};
a c();
template  a fn2() {
 int d;
 return c() << d;
}

gcc accepts the code, but clang rejects it:

 error: 'operator<<' is a private member of 'a'
  return c() << d;
 ~~~ ^  ~
 note: implicitly declared private here
  template  a <<(b);
   ^
1 error generated.

BTW, I constructed a related code sample:

#include
using namespace std;
class A
{
public:
A():value(0){cout<<"i am gouzao"<  ++(int)
{
cout<<"A++"< std::basic_ostream<_CharT, _Traits>&
std::operator<<(std::basic_ostream<_CharT, _Traits>&, const
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
 operator<<(basic_ostream<_CharT, _Traits>& __os,
 ^~~~
/usr/include/c++/7/bits/basic_string.h:6284:5: note:   template argument
deduction/substitution failed:
test.cpp:33:8: note:   ‘A’ is not derived from ‘std::basic_ostream<_CharT,
_Traits>’
 a<<1;
^
In file included from /usr/include/c++/7/bits/ios_base.h:46:0,
 from /usr/include/c++/7/ios:42,
 from /usr/include/c++/7/ostream:38,
 from /usr/include/c++/7/iostream:39,
 from test.cpp:1:
/usr/include/c++/7/system_error:217:5: note: candidate: template std::basic_ostream<_CharT, _Traits>&
std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::error_code&)
 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
 ^~~~
/usr/include/c++/7/system_error:217:5: note:   template argument
deduction/substitution failed:
test.cpp:33:8: note:   ‘A’ is not derived from ‘std::basic_ostream<_CharT,
_Traits>’
 a<<1;
^
In file included from /usr/include/c++/7/iostream:39:0,
 from test.cpp:1:
/usr/include/c++/7/ostream:497:5: note: candidate: template std::basic_ostream<_CharT, _Traits>&
std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
 ^~~~
/usr/include/c++/7/ostream:497:5: note:   template argument
deduction/substitution failed:
test.cpp:33:8: note:   ‘A’ is not derived from ‘std::basic_ostream<_CharT,
_Traits>’
 a<<1;
^
In file included from /usr/include/c++/7/iostream:39:0,
 from test.cpp:1:
/usr/include/c++/7/ostream:502:5: note: candidate: template std::basic_ostream<_CharT, _Traits>&
std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
 operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
 ^~~~
/usr/include/c++/7/ostream:502:5: note:   template argument
deduction/substitution failed:
test.cpp:33:8: note:   ‘A’ is not derived from ‘std::basic_ostream<_CharT,
_Traits>’
 a<<1;
^
In file included from /usr/include/c++/7/iostream:39:0,
 from test.cpp:1:
/usr/include/c++/7/ostream:508:5: note: candidate: template
std::basic_ostream& std::operator<<(std::basic_ostream&, char)
 operator<<(basic_ostream& __out, char __c)
 ^~~~
/usr/include/c++/7/ostream:508:5: note:   template argument
deduction/substitution failed:
test.cpp:33:8: note:   ‘A’ is not derived from ‘std::basic_ostream’
 a<<1;
^
In file included from /usr/include/c++/7/iostream:39:0,
 from test.cpp:1:
/usr/include/c++/7/ostream:514:5: note: candidate: template
std::basic_ostream& std::operator<<(std::basic_ostream&, signed char)
 operator<<(basic_ostream& __out, signed char __c)
 ^~~~
/usr/include/c++/7/ostream:514:5: note:   template argument
deduction/substitution failed:
test.cpp:33:8: note:   ‘A’ is not derived from ‘std::basic_ostream’
 a<<1;
^
In file included from /usr/include/c++/7/iostream:39:0,
 from test.cpp:1:
/usr/include/c++/7/ostream:519:5: note: candidate: template
std::basic_ostream& std::operator<<(std::basic_ostream&, unsigned char)
 operator<<(basic_ostream& __out, unsigned char __c)
 ^~~~
/usr/include/c++/7/ostream:519:5: note:   template argument
deduction/substitution failed:
test.cpp:33:8: note:   ‘A’ is not derived from ‘std::basic_ostream’
 a<<1;
^
In file included from /usr/include/c++/7/

[Bug c++/90854] New: Gcc fails to compile a code sample for some parameters

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90854

Bug ID: 90854
   Summary: Gcc fails to compile a code sample for some parameters
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

class A
{
 int m_fn1 (void *);
 int m_fn2 (bool);
};
inline int
A::m_fn2 (bool)
{
 static __attribute__ ((section (""))) int a;
 if (a)
 ;
 return 0;
}

int
A::m_fn1 (void *)
{
 return m_fn2 (0);
}

gcc accepts the code, with some parameters: gcc -Os | gcc -O3 | gcc -O1 | gcc
-Asystem=posix | gcc -Wstrict-prototypes 

Meanwhile, it rejects it with others parameters: g++ -O0 | g++ -Dlinux | g++
-Wwrite-strings | g++ -Amachine=i386 | g++ -Wpointer-arith

The error message is strange:
/tmp/ccIBuqiz.s: Assembler messages:
/tmp/ccIBuqiz.s:4: Error: missing name

[Bug c++/90853] New: -O3 complains already defined symbol

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90853

Bug ID: 90853
   Summary: -O3 complains already defined symbol
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

void x();
void rgb2yuv16bit_mmx422_row();

void x()
{
  rgb2yuv16bit_mmx422_row();
}

void rgb2yuv16bit_mmx422_row()
{
  __asm__ __volatile__ (
  "rgb2yuv16_422:\n"
  );
}

gcc accepts the code, but with -O3, it rejects it:

x.cpp: Assembler messages:
x.cpp:13: Error: symbol `rgb2yuv16_422' is already defined

[Bug c++/90852] New: A recurring bug: Constant expressions support reinterpret_cast

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90852

Bug ID: 90852
   Summary: A recurring bug: Constant expressions support
reinterpret_cast
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

A previous bug report (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49171)
contains two samples:

//---
constexpr const char* c = reinterpret_cast(0x123);
//---


//
struct X {
 X* operator&();
};

X x[2];

const bool p = (reinterpret_cast(_cast(x[1]))
- reinterpret_cast(_cast(x[0]))) == sizeof(X);

enum E { e = p }; // e should have a value equal to 1
//


After some discussions, programmers agree that the first sample shall be
reject, but the second sample has its value. gcc 7.2 accepts the code. However,
gcc 10.0.0 rejects it:

source>:10:14: error: the value of 'p' is not usable in a constant expression

   10 | enum E { e = p }; // e should have a value equal to 1

  |  ^

:7:12: note: 'p' was not initialized with a constant expression

7 | const bool p = (reinterpret_cast(_cast(x[1]))

  |^

:10:14: error: the value of 'p' is not usable in a constant expression

   10 | enum E { e = p }; // e should have a value equal to 1

  |  ^

:7:12: note: 'p' was not initialized with a constant expression

7 | const bool p = (reinterpret_cast(_cast(x[1]))

  |^

:10:14: error: enumerator value for 'e' is not an integer constant

   10 | enum E { e = p }; // e should have a value equal to 1

  |  ^

Compiler returned: 1

[Bug c++/90851] New: -O3 overflow

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90851

Bug ID: 90851
   Summary: -O3 overflow
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:


struct S { S (); S (int); ~S (); int i; };
struct A { S s[10]; };

void
foo ()
{
 A a = {{}};
}


It takes several minutes to compile the code. With the following parameters:
g++ -Os | g++ -O3 | gcc -Os | gcc -O3 |, I got a overflow:

cc1plus: out of memory allocating 65536 bytes after a total of 58655244288
bytes

[Bug c++/90850] New: template parameters do not match

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90850

Bug ID: 90850
   Summary: template parameters do not match
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

template
class C
{
 template
 class C2 { };
};

template<> template
class C::C2 { };
template<> template
class C::C2 { };

gcc accepts the code. icc:

(8): error: too many template parameters -- does not match previous
declaration (declared at line 4)

  template<> template

 ^

(10): error: declaration is incompatible with template parameter "T2"
(declared at line 4)

  template<> template

 ^

compilation aborted for  (code 2)

Compiler returned: 2

clang rejects it:

source>:8:12: error: too many template parameters in template redeclaration

template<> template

   ^~

:4:2: note: previous template declaration is here

 template

 ^~

:10:24: error: template parameter has a different kind in template
redeclaration

template<> template

   ^

:4:17: note: previous template declaration is here

 template

^

2 errors generated.

Compiler returned: 1


clang rejects it:

[Bug c++/90849] New: Gcc accepts invalid code

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90849

Bug ID: 90849
   Summary: Gcc accepts invalid code
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

template < typename = void > 
class A 
{
public:
 A () : f0 ( 1 ) { }
 A (int);

private:
 typedef A<> f0;
};

A<> a;

The code comes from a previous bug report:

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

It is said to be invalid and it triggers a ICE. The bug is marked as fixed. I
tried gcc 10.0.0, it accepts the code. If it is invalid, gcc shall reject it.
BTW, clang reject it:

:5:9: error: type 'A::f0' (aka 'A<>') is not a direct or virtual base
of 'A'

 A () : f0 ( 1 ) { }

^~

1 error generated.

Compiler returned: 1

[Bug c++/90848] New: A recurring bug: Overeager application of conversion to function pointer during overload resolution of call to function object

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90848

Bug ID: 90848
   Summary: A recurring bug: Overeager application of conversion
to function pointer during overload resolution of call
to function object
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

A bug report (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71117) complains
that GCC accepts the code:

template using id = T;
struct F {
  template operator id();
} f;
int n = f(0);


Clang, EDG, MSVC reject it. Some comments are as follows:

"Per [over.call.object]/2, I think GCC is wrong per the current language
wording. A conversion function template does not qualify as a "non-explicit
conversion function declared in [F or base class thereof]" (because it is not a
conversion function), and nor does a specialization of one (because it is not
itself declared in F).

I also don't see any way the current wording would take us to
[temp.deduct.conv] for this case, nor how that wording would apply (since we
don't have a function type that's required as the result of the conversion).
Perhaps GCC is following the rules of [temp.deduct.call] in this case, treating
the (pointee type of the) result type of the conversion function as if it were
the function type of the callee?

In the abstract, GCC's approach to this situation seems superior -- it's able
to use a conversion to function pointer in many cases where other compilers
can't -- but I'm a little hesitant to suggest we adopt that approach since it
breaks examples like yours."

I tried gcc 10.0.0. It still accepts it, although the above bug is marked as
fixed.

[Bug c++/90847] New: requested alignment is not an integer constant

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90847

Bug ID: 90847
   Summary: requested alignment is not an integer constant
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

template  
void test() {
 constexpr int N2 = N;
 typedef int T alignas(N2);
 // error: requested alignment is not an integer constant
}

int main() {
 test<4>();
 return 0;
}

gcc accepts the code. clang rejects it:
source>:4:16: error: 'alignas' attribute only applies to variables, data
members and tag types

 typedef int T alignas(N2);

   ^

1 error generated.

Compiler returned: 1

icc gives a warning:
(4): warning #3463: alignas does not apply here

   typedef int T alignas(N2);

 ^

Compiler returned: 0

[Bug c++/90845] New: A recurring hang: braces around scalar initializer - should be a warning

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90845

Bug ID: 90845
   Summary: A recurring hang: braces around scalar initializer -
should be a warning
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

A bug report complains that gcc shall warn braces around scalar initializer,
and a test case is as follows:

 struct SA { int n[1]; };
 SA sa{{{0}}}; // GCC error - should be warning

It is marked as fixed. My gcc is 10.0.0, and with -c, I cannot find any
warnings.

The url of the bug report:

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

[Bug c++/90833] Inline specification is changed?

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90833

--- Comment #1 from zhonghao at pku dot org.cn ---
Here is the url of the previous bug report:

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


(In reply to zhonghao from comment #0)
> A previous bug report has a code sample:
> 
> int main()
>   {
> extern inline void f();
>   }
> 
>   void f()
>   {
>   }
> 
> It says that gcc rejects the sample, but clang accepts it. The bug is marked
> as fixed. 
> 
> I tried gcc 10.0.0 and clang 9.0.0. Now, gcc accepts the code, but clang
> rejects it:
> 
> error: inline declaration of 'f' not allowed in block scope
>  extern inline void f();
> ^~~
> 1 error generated.
> 
> Is the spec changed? Or, actually, this is a new bug?

[Bug c++/90833] New: Inline specification is changed?

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90833

Bug ID: 90833
   Summary: Inline specification is changed?
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

A previous bug report has a code sample:

int main()
  {
extern inline void f();
  }

  void f()
  {
  }

It says that gcc rejects the sample, but clang accepts it. The bug is marked as
fixed. 

I tried gcc 10.0.0 and clang 9.0.0. Now, gcc accepts the code, but clang
rejects it:

error: inline declaration of 'f' not allowed in block scope
 extern inline void f();
^~~
1 error generated.

Is the spec changed? Or, actually, this is a new bug?

[Bug c++/90832] New: An ICE

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90832

Bug ID: 90832
   Summary: An ICE
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

class B
{
 template  friend struct A;
 B() {}
};

template 
struct A
{
 A() noexcept(sizeof(B{})) { }
};

struct C
{
 C()
 {
 static_assert( sizeof(A{}), "" );
 }
};

The error message:

gcc: internal compiler error: Segmentation fault signal terminated program
cc1plus
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

[Bug c++/90830] New: A not fully fixed ICE?

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90830

Bug ID: 90830
   Summary: A not fully fixed ICE?
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The bug report fixed a ICE:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70449

template  
constexpr int f ()
{
  enum E { a = f<0> () };
  return 0; 
}

Given the code, gcc 10.0.0 rejects the code:

: In instantiation of 'constexpr int f() [with int I = 0]':

:4:21:   required from here

:4:21: error: 'constexpr int f() [with int I = 0]' called in a constant
expression before its definition is complete

4 |   enum E { a = f<0> () };

  |~^~

:4:8: error: enumerator value for 'a' is not an integer constant

4 |   enum E { a = f<0> () };

  |^

Compiler returned: 1

However, I tried clang and icc, and both compilers accept the code. Is the bug
fully fixed?

[Bug c++/90829] New: -fopenacc expects iteration declaration or initialization

2019-06-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90829

Bug ID: 90829
   Summary: -fopenacc  expects iteration declaration or
initialization
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

void foo(float *f, double *r) {
#pragma acc kernels loop create(f) copy(r)
for(;;) {}
}

gcc accepts the code, but with -fopenacc, it rejects it:

: In function 'void foo(float*, double*)':

:3:1: error: expected iteration declaration or initialization

3 | for(;;) {}

  | ^~~

Compiler returned: 1

Shall programmers explicitly provide iteration declaration or initialization,
with -fopenacc? If it is case, it is worth mentioning the requirement in its
manual.

[Bug c++/90828] New: A recurring hang when mangling

2019-06-10 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90828

Bug ID: 90828
   Summary: A recurring hang when mangling
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

A bug report complains that there is endless recursion during mangling.

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

It is marked as fixed. My gcc is 10.0.0. It takes me hours, but still cannot
compile the test code:

typedef int octave_idx_type;
extern "C" double sqrt (double);
namespace std
{
  double abs (double __x)
  {
return __builtin_fabs (__x);
  }
  using::sqrt;
  template  _Tp  (_Tp &__a, _Tp &__b)
  {
if (__a < __b)
  return __b;
return __a;
  }
}

extern "C" int __lo_ieee_isinf (double);
extern "C" int __lo_ieee_float_isinf ();

class dim_vector
{
protected:class dim_vector_rep
  {
  public:octave_idx_type dims;
int count;
  dim_vector_rep (octave_idx_type r, octave_idx_type):dims (), count ()
{
}
  };
  dim_vector_rep * rep;
private:dim_vector_rep nil_rep ()
  {
  }
public:
  dim_vector ()
  {
  }
dim_vector (octave_idx_type r, octave_idx_type c):rep
(new
 dim_vector_rep (r, c))
  {
  }
  ~dim_vector ()
  {
delete rep;
  }
};
namespace std
{
  struct __numeric_limits_base
  {
  };
  template  struct numeric_limits:public __numeric_limits_base
  {
static _Tp epsilon () throw ()
{
}
  };
}

template  class Array
{
protected:class ArrayRep
  {
  public:T * data;
int count;
  ArrayRep (octave_idx_type n):data (new T[n]), count ()
{
}
  };
  Array::ArrayRep * rep;
  dim_vector dimensions;
  T slice_data;
  octave_idx_type slice_len;
public: Array (dim_vector dv):rep
(new Array ::ArrayRep (get_size (dv)))
  {
  }
Array (dim_vector dv, T):rep
(Array
 ::ArrayRep (get_size ())), dimensions ()
  {
  }
  octave_idx_type capacity ()
  {
return slice_len;
  }
  octave_idx_type nelem ()
  {
return capacity ();
  }
  octave_idx_type numel ()
  {
return nelem ();
  }
  octave_idx_type get_size (dim_vector);
  T xelem (octave_idx_type n)
  {
slice_data[n];
  }
  T elem ()
  {
xelem ();
  }
  T operator ()()
  {
elem ();
  }
};
template  class Array2:public Array 
{
public:
Array2 ():Array  (dim_vector (0, 0))
  {
  }
Array2 (octave_idx_type r, octave_idx_type c):Array
 (dim_vector (r, c))
  {
  }
Array2 (octave_idx_type r, octave_idx_type c, T):Array
 (dim_vector ())
  {
  }
};
template  class MArray2:public Array2 
{
public: MArray2 ():Array2  ()
  {
  }
MArray2 (octave_idx_type n, octave_idx_type m):Array2  (n, m)
  {
  }
MArray2 (octave_idx_type n, octave_idx_type m, T):Array2  ()
  {
  }
};
template  class MArray:public Array 
{
};
class Matrix:public MArray2 
{
public:typedef void (solve_singularity_handler) ();
Matrix ():MArray2 ()
  {
  }
  Matrix (octave_idx_type r, octave_idx_type c):MArray2 (r, c)
  {
  }
  Matrix (octave_idx_type r, octave_idx_type c, double val):MArray2 (r, val)
  {
  }
};
class ColumnVector:public MArray 
{
};
template  class Sparse
{
protected:class SparseRep
  {
  };
public:typename Sparse ::SparseRep rep;
  octave_idx_type rows ()
  {
  }
};
template  class MSparse:public Sparse 
{
};
class SparseMatrix:public MSparse 
{
};
template  class norm_accumulator_2
{
  R scl, sum;
public:
norm_accumulator_2 ():scl (), sum ()
  {
  }
  void accum (R val)
  {
R t = std::abs (val);
if (scl == t)
  sum += 1;
  }
  operator R ()
  {
sqrt (sum);
  }
};
template  class norm_accumulator_1
{
  R sum;
public:
norm_accumulator_1 ():sum ()
  {
  }
  template  void accum (U val)
  {
sum += std::abs (val);
  }
  operator R ()
  {;
  }
};
template  class norm_accumulator_inf
{
  R max;
public:
norm_accumulator_inf ():max ()
  {
  }
  template  void accum (U val)
  {
double m = std::abs (val);
max = std::max (max, m);
  }
  operator R ()
  {
return max;
  }
};
template  class norm_accumulator_0
{
  unsigned num;
public:
norm_accumulator_0 ():num ()
  {
  }
  template  void accum (U)
  {
  }
  operator R ()
  {
return num;
  }
};
template  void vector_norm (Array  , R ,
ACC acc)
{
  for (octave_idx_type i = 0; i < v.numel (); i++)
acc.accum ((i));
  res = acc;
}

template  R vector_norm (MArray  , R)
{
  R res;
  vector_norm (v, norm_accumulator_2  ());
}

template  R vector_norm (MArray2  , R p)
{
  R res;
  if (p == 2)
vector_norm (v, res, norm_accumulator_2  ());
  else if (p == 1)
vector_norm (v, res, norm_accumulator_1  ());
  else if (((p) == sizeof (float) ? (p) : __lo_ieee_isinf (p)))
{
  if (p> 0)
vector_norm (v, res, norm_accumulator_inf  ());
}
  else if (p == 0)
vector_norm (v, res, norm_accumulator_0  ());
  return res;
}

template 
R higham (MatrixT m, 

[Bug c++/90807] New: Wrong debug message

2019-06-10 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90807

Bug ID: 90807
   Summary: Wrong debug message
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and my code is:

void f() {
 union {
 typeof
 (
 (
 {
 unsigned long __ptr;
 (int *)(0);
 }
 )
 )
 __val;
 };
}


gcc rejects it with the following message:

x86-64 gcc (trunk)
1

No Results
x86-64 gcc (trunk)
- cached

#1 with x86-64 gcc (trunk)

: In function 'void f()':

:5:2: error: statement-expressions are not allowed outside functions
nor in template-argument lists

5 |  (

  |  ^

Compiler returned: 1

The message seems to be wrong, since the statement-expression here is inside a
function and not inside a template-argument-list.

BTW, the code does not violate any of the rules in
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html). Clang accepts the
code. Do you intend to allow statement-expressions inside function-local type
definitions or not.

[Bug c++/90805] New: Overflow in switch case is not detected

2019-06-09 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90805

Bug ID: 90805
   Summary: Overflow in switch case is not detected
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

int f(int cmd)
{
 switch (cmd) {
 case 0x8018U:
 return 1;
 }
 return 0;
}

gcc accepts the code, but clang can detect its overflow:

:4:7: error: case value evaluates to 2149056512, which cannot be
narrowed to type 'int' [-Wc++11-narrowing]

 case 0x8018U:

  ^

1 error generated.

Compiler returned: 1

[Bug c++/90804] New: function declaration cannot have variably modified type

2019-06-09 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90804

Bug ID: 90804
   Summary: function declaration cannot have variably modified
type
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

int a(int b) {int (*c(void))[b];**c() = 2;}

gcc accepts the code, but clang, icc, and msvc all reject it:

clang:
source>:1:21: error: function declaration cannot have variably modified type

int a(int b) {int (*c(void))[b];**c() = 2;}

^

1 error generated.

Compiler returned: 1

icc:
(1): error: an entity with linkage cannot have a type involving a
variable length array

  int a(int b) {int (*c(void))[b];**c() = 2;}

  ^

compilation aborted for  (code 2)

Compiler returned: 2

msvc:

example.cpp

(1): error C2131: expression did not evaluate to a constant

(1): note: failure was caused by a read of a variable outside its
lifetime

(1): note: see usage of 'b'

Compiler returned: 2

[Bug c++/90803] New: gcc accepts invalid code

2019-06-09 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90803

Bug ID: 90803
   Summary: gcc accepts invalid code
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:


struct S {};
struct T : S {};
void foo(T *t) { t->~S(); }

gcc accepts the code, but icc, msvc, and clang all reject it.

msvc:
(3): error C2300: 'T': class does not have a destructor called '~S'

Compiler returned: 2

icc:

source>(3): error: invalid destructor name for type "T"

  void foo(T *t) { t->~S(); }

   ^

compilation aborted for  (code 2)

Compiler returned: 2

clang:

source>:3:22: error: destructor type 'S' in object destruction expression does
not match the type 'T' of the object being destroyed

void foo(T *t) { t->~S(); }

 ^

:1:8: note: type 'S' is declared here

struct S {};

   ^

1 error generated.

Compiler returned: 1

[Bug c++/90802] New: optimization accepts invalid

2019-06-09 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90802

Bug ID: 90802
   Summary: optimization accepts invalid
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

typedef unsigned int uint32_t;
struct CPUPPCState
{
 uint32_t fpscr;
};
register struct CPUPPCState *env __asm__ ("ebp");
void
helpersetbit (uint32_t bit)
{
 switch (bit)
 switch (env->fpscr)
 {
 }
}

Gcc rejects it:

source>: In function 'void helpersetbit(uint32_t)':

:11:15: warning: statement will never be executed
[-Wswitch-unreachable]

   11 |  switch (env->fpscr)

  |  ~^

:8:1: error: frame pointer required, but reserved

8 | helpersetbit (uint32_t bit)

  | ^~~~

:6:30: note: for 'env'

6 | register struct CPUPPCState *env __asm__ ("ebp");

  |  ^~~

Compiler returned: 1

However, it accepts the above code, with the following parameters:

gcc -fomit-frame-pointer | gcc -Os | gcc -O3 | gcc -O1 | g++
-fomit-frame-pointer | g++ -Os | g++ -O3 | g++ -O1 | 


The above error message contains a warning for dead code. I submitted another
bug, which can be related:

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

[Bug c++/90801] A recurring hang

2019-06-09 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90801

--- Comment #1 from zhonghao at pku dot org.cn ---
Here is the url of the previous bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59659

(In reply to zhonghao from comment #0)
> A previous bug report complains that gcc hangs when compiling large
> zero-initialized std::array, and it is marked as fixed. My gcc is 10.0.0,
> but it still hangs given the following code sample:
> 
> #include 
> 
> class Foo { public: Foo() {} int i; };
> 
> int main() {
>  std::array arr = {{}}; // Halting problem.
> }

[Bug c++/90801] New: A recurring hang

2019-06-09 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90801

Bug ID: 90801
   Summary: A recurring hang
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

A previous bug report complains that gcc hangs when compiling large
zero-initialized std::array, and it is marked as fixed. My gcc is 10.0.0, but
it still hangs given the following code sample:

#include 

class Foo { public: Foo() {} int i; };

int main() {
 std::array arr = {{}}; // Halting problem.
}

[Bug c++/90798] New: An ICE with -Os

2019-06-09 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90798

Bug ID: 90798
   Summary: An ICE with -Os
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and my code is:

#include 
#include 

void gather_swizzle(const __m128i *indices, float *buffer)
{
 __m128i idx = *indices++;
 uint32_t idx0 = static_cast(_mm_extract_epi32(idx, 0));
 uint32_t idx1 = static_cast(_mm_extract_epi32(idx, 1));
 uint32_t idx2 = static_cast(_mm_extract_epi32(idx, 2));
 uint32_t idx3 = static_cast(_mm_extract_epi32(idx, 3));

 float sum0 = buffer[idx0];
 float sum1 = buffer[idx1];
 float sum2 = buffer[idx2];
 float sum3 = buffer[idx3];

 buffer[0] = sum0;
 buffer[1] = sum1;
 buffer[2] = sum2;
 buffer[3] = sum3;
}

Gcc crashes, with the following parameters:

g++ -Os | g++ -O3 | g++ -O1 | gcc -Os | gcc -O3 | gcc -O1 | 

n file included from
/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/immintrin.h:37,

 from
/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/x86intrin.h:32,

 from :1:

/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/smmintrin.h:
In function 'void gather_swizzle(const __m128i*, float*)':

/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/smmintrin.h:447:1:
error: inlining failed in call to 'always_inline' 'int
_mm_extract_epi32(__m128i, int)': target specific option mismatch

  447 | _mm_extract_epi32 (__m128i __X, const int __N)

  | ^

:10:57: note: called from here

   10 |  uint32_t idx3 = static_cast(_mm_extract_epi32(idx, 3));

  |~^~~~

In file included from
/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/immintrin.h:37,

 from
/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/x86intrin.h:32,

 from :1:

/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/smmintrin.h:447:1:
error: inlining failed in call to 'always_inline' 'int
_mm_extract_epi32(__m128i, int)': target specific option mismatch

  447 | _mm_extract_epi32 (__m128i __X, const int __N)

  | ^

:9:57: note: called from here

9 |  uint32_t idx2 = static_cast(_mm_extract_epi32(idx, 2));

  |~^~~~

In file included from
/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/immintrin.h:37,

 from
/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/x86intrin.h:32,

 from :1:

/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/smmintrin.h:447:1:
error: inlining failed in call to 'always_inline' 'int
_mm_extract_epi32(__m128i, int)': target specific option mismatch

  447 | _mm_extract_epi32 (__m128i __X, const int __N)

  | ^

:8:57: note: called from here

8 |  uint32_t idx1 = static_cast(_mm_extract_epi32(idx, 1));

  |~^~~~

In file included from
/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/immintrin.h:37,

 from
/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/x86intrin.h:32,

 from :1:

/opt/compiler-explorer/gcc-trunk-20190609/lib/gcc/x86_64-linux-gnu/10.0.0/include/smmintrin.h:447:1:
error: inlining failed in call to 'always_inline' 'int
_mm_extract_epi32(__m128i, int)': target specific option mismatch

  447 | _mm_extract_epi32 (__m128i __X, const int __N)

  | ^

:7:57: note: called from here

7 |  uint32_t idx0 = static_cast(_mm_extract_epi32(idx, 0));

  |~^~~~

Compiler returned: 1

[Bug c++/90797] New: gcc reject valid code

2019-06-09 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90797

Bug ID: 90797
   Summary: gcc reject valid code
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and my code is:

class a {
 public:
 int b(int a());
};
int x();
void y() {
 a z; z.b(x);
}

The error message is:

:3:8: error: return type specification for constructor invalid

3 |  int b(int a());

  |^~~

: In function 'void y()':

:7:11: error: invalid conversion from 'int (*)()' to 'void (*)()'
[-fpermissive]

7 |  a z; z.b(x);

  |   ^

  |   |

  |   int (*)()

:3:12: note:   initializing argument 1 of 'int a::b(void (*)())'

3 |  int b(int a());

  |^~~

Compiler returned: 1

clang, icc, and msvc all accept the code.

[Bug c++/90794] New: adding -O3 leads to crash

2019-06-08 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90794

Bug ID: 90794
   Summary: adding -O3 leads to crash
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and my code is:

#include 

int run(int sz)
{
 typedef double MAT[sz][sz];
 MAT *a;
 a = (MAT*) malloc(sizeof(MAT));
 return (a==0);
}

int main(int argc, char* argv[])
{
 return run(500);
}

I compiles well, but after adding -O3, it crashes:
: In function ‘int main(int, char**)’:
: internal compiler error: Segmentation fault
   11 | int main(int argc, char* argv[])
  | ^~~~
0xb3badf crash_signal
../../9.1/gcc/toplev.c:326
0xc1660d has_zero_uses
../../9.1/gcc/ssa-iterators.h:389
0xc1660d coalesce_with_default
../../9.1/gcc/tree-ssa-coalesce.c:1019
0xc1660d populate_coalesce_list_for_outofssa
../../9.1/gcc/tree-ssa-coalesce.c:1241
0xc1660d coalesce_ssa_name(_var_map*)
../../9.1/gcc/tree-ssa-coalesce.c:1709
0xbc96eb remove_ssa_form
../../9.1/gcc/tree-outof-ssa.c:1031
0xbc96eb rewrite_out_of_ssa(ssaexpand*)
../../9.1/gcc/tree-outof-ssa.c:1289
0x7b8500 execute
../../9.1/gcc/cfgexpand.c:6327
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

[Bug c++/90793] New: adding -fPIC leads to compilation error

2019-06-08 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90793

Bug ID: 90793
   Summary: adding -fPIC leads to compilation error
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and my code is:

void
f(void)
{
 __asm volatile("" : : "i" (f));
}

It compiles well, but after adding -fPIC, I got a message:

source>: In function 'void f()':

:4:32: warning: 'asm' operand 0 probably does not match constraints

4 |  __asm volatile("" : : "i" (f));

  |^

:4:32: error: impossible constraint in 'asm'

Compiler returned: 1

[Bug c++/90791] New: -Os accepts wrong code

2019-06-08 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90791

Bug ID: 90791
   Summary: -Os accepts wrong code
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and my code is:

void x()
{
 int a;
 __asm__ (
 "%0 %1"
 :"=r"(a));
}

gcc accepts the code with the following parameters:

gcc -Os | gcc -O3 | gcc -O1 | g++ -Os | g++ -O3 | g++ -O1 | 

With other parameters, it rejects the code:

: In function 'void x()':

:6:11: error: invalid 'asm': operand number out of range

6 |  :"=r"(a));

  |   ^

Compiler returned: 1

[Bug c++/90790] New: Using override on a private overridden destructor shall produce an error

2019-06-08 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90790

Bug ID: 90790
   Summary: Using override on a private overridden destructor
shall produce an error
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

This code:

class Base
{
virtual ~Base() = default;
};

class Derived : public Base
{
~Derived() override = default;
};

My gcc is 10.0.0, and it accepts the code. clang++ rejects its with the
message:

:8:2: error: deleted function '~Derived' cannot override a non-deleted
function

 ~Derived() override = default;

 ^

:3:10: note: overridden virtual function is here

 virtual ~Base() = default;

 ^

:6:17: note: destructor of 'Derived' is implicitly deleted because base
class 'Base' has an inaccessible destructor

class Derived : public Base

^

:8:2: warning: explicitly defaulted destructor is implicitly deleted
[-Wdefaulted-function-deleted]

 ~Derived() override = default;

 ^

:6:17: note: destructor of 'Derived' is implicitly deleted because base
class 'Base' has an inaccessible destructor

class Derived : public Base

^

1 warning and 1 error generated.

Compiler returned: 1

msvc also rejects the code:

source>(9): warning C4624: 'Derived': destructor was implicitly defined as
deleted

(8): error C2282: 'Derived::~Derived' cannot override 'Base::~Base'

(3): note: 'Base::~Base' is not deleted

The code sample comes from https://bugs.llvm.org/show_bug.cgi?id=30844

David Blaikie makes a comments: Because the base class dtor is private, the
explicitly defaulted derived class dtor is defined as deleted (since it can't
be defined as anything else - because the base class dtor is inaccessible for
it to access, so the derived dtor can't be implemented).

His argument seems to be correct.

[Bug c++/90789] gcc complains cannot capture 'f()()' by reference on valid code

2019-06-08 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90789

zhonghao at pku dot org.cn changed:

   What|Removed |Added

Summary|gcc |gcc complains cannot
   ||capture 'f()()' by
   ||reference on valid code

--- Comment #1 from zhonghao at pku dot org.cn ---
My gcc is 10.0.0, and the code is:

#include 
struct S { ~S() { std::cout << "dtor\n"; } };
const S f() { return {}; }
int main() {
 [(f())]{ std::cout << "in lambda\n"; }();
 std::cout << "end of main\n";
}

The error message is:
: In function 'int main()':

:5:9: error: cannot capture 'f()()' by reference

5 |  [(f())]{ std::cout << "in lambda\n"; }();

  | ^

Compiler returned: 1

I tried clang, icc, and msvc. They all accept the code.

[Bug c++/90789] New: gcc

2019-06-08 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90789

Bug ID: 90789
   Summary: gcc
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

[Bug c++/90776] g++ -fms-extensions is inconsistent with Microsoft's compiler

2019-06-07 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90776

--- Comment #3 from zhonghao at pku dot org.cn ---
Shall g++ be compatible with Microsoft's compiler, when -fms-extensions is set?

(In reply to Jonathan Wakely from comment #2)
> Why do you think either of these should be accepted?

[Bug c++/90776] g++ -fms-extensions is inconsistent with Microsoft's compiler

2019-06-06 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90776

--- Comment #1 from zhonghao at pku dot org.cn ---
Another code sample:

typedef union __declspec(align(64)) foo_t {
 double a[8];
} foo_t;

foo_t bar;

[Bug c++/90776] New: g++ -fms-extensions is inconsistent with Microsoft's compiler

2019-06-06 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90776

Bug ID: 90776
   Summary: g++ -fms-extensions is inconsistent with Microsoft's
compiler
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is:

typedef struct a {} A;

void f() {
 if (__builtin_alignof(A))
 ;
}

g++ -fms-extensions rejects the code:

 error: ‘__builtin_alignof’ was not declared in this scope; did you mean
‘__builtin_asinhf’?
4 |  if (__builtin_alignof(A))
  |  ^
  |  __builtin_asinhf

clang++ -fms-extensions accepts the code, and Microsoft's compiler also accepts
the code:

https://godbolt.org/z/HIAYtj

Another code sample is:

class __declspec(dllexport) A
{};

g++ rejects the code:

 error: expected initializer before ‘A’
1 | class __declspec(dllexport) A
  |  

Microsoft's compiler accepts it.

[Bug c++/90775] New: A inconsistent compilation result

2019-06-06 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90775

Bug ID: 90775
   Summary: A inconsistent compilation result
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My g++ is 10.0.0, and my code is as follows:

#include 
#include 
struct S {};
int begin(S);
template std::true_type has_cbegin(decltype(std::cbegin(T{})));
template std::false_type has_cbegin(...);
static_assert(!decltype(has_cbegin(0))::value);

When compiling with -c -std=c++14, it accepts the code. However, when compiling
with -c -std=c++11 or -c -std=c++0x

/home/haozhong/project/approach/compilerpara/llvm/tmp/llvm_28927/code0.c.cpp:5:59:error:‘cbegin’
is not a member of ‘std’; did you mean ‘begin’?
5 | template std::true_type
has_cbegin(decltype(std::cbegin(T{})));
  |   ^~
  |   begin
/home/haozhong/project/approach/compilerpara/llvm/tmp/llvm_28927/code0.c.cpp:5:59:
error:‘cbegin’ is not a member of ‘std’; did you mean ‘begin’?
5 | template std::true_type
has_cbegin(decltype(std::cbegin(T{})));
  |   ^~
  |   begin
/home/haozhong/project/approach/compilerpara/llvm/tmp/llvm_28927/code0.c.cpp:7:15:
error: static assertion failed
7 | static_assert(!decltype(has_cbegin(0))::value);
  |   ^~

Something wrong with -std=c++14?

[Bug c++/86503] Segmentation fault signal terminated

2018-08-08 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86503

--- Comment #3 from zhonghao at pku dot org.cn ---
(In reply to Richard Biener from comment #1)
> You run out of memory or stack.  Try ulimit -s unlimited

I tried  ulimit -s unlimited. This time, the error messages are as follows:

g++ -ftemplate-depth=100 test.cpp 
test.cpp: In substitution of 'template __typeof__ (ft(F(), 0)) ft(F, typename enable_if<(n != 0), int>::type) [with F =
main()::a*; int n = -97]':
test.cpp:14:21:   recursively required by substitution of 'template __typeof__ (ft(F(), 0)) ft(F, typename enable_if<(n != 0),
int>::type) [with F = main()::a*; int n = 1]'
test.cpp:14:21:   required by substitution of 'template
__typeof__ (ft(F(), 0)) ft(F, typename enable_if<(n != 0),
int>::type) [with F = main()::a*; int n = 2]'
test.cpp:18:30:   required from here
test.cpp:14:21: fatal error: template instantiation depth exceeds maximum of
100 (use -ftemplate-depth= to increase the maximum)
 typeof( ft< F, n-1 >( F(), 0 ) )
   ~~^~~~
compilation terminated.

[Bug c++/86181] static object mangling conflicts

2018-08-07 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86181

--- Comment #2 from zhonghao at pku dot org.cn ---
I reported the code to llvm. A developer of llvm said:

Clang follows the agreed direction for CWG issue 1839, which says that
redeclaration lookup for 'extern int i;' finds the 'static int i;' declared at
namespace scope and thus the internal linkage is inherited.


Does gcc follow a different lookup?

[Bug middle-end/86718] [9 Regression] ICE during RTL pass: expand

2018-08-06 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86718

--- Comment #2 from zhonghao at pku dot org.cn ---
My gcc:
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc9.0/configure --enable-languages=c,c++
--disable-multilib
Thread model: posix
gcc version 9.0.0 20180715 (experimental) (GCC)

[Bug c/86729] New: address of vector element requested

2018-07-30 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86729

Bug ID: 86729
   Summary: address of vector element requested
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

gcc accepts the following code:

void a() {
 typedef float v4sf __attribute__ ((vector_size (16)));
 static v4sf q;
 float* r = [0];
}

clang rejects it:

clang code1.c 
code1.c:4:13: error: address of vector element requested
 float* r = [0];
^
1 error generated.


The error message of clang seems to be reasonable?

[Bug c/86721] New: use of undeclared identifier

2018-07-29 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86721

Bug ID: 86721
   Summary: use of undeclared identifier
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

void g() {
 __builtin_printf(
 u8R"abcd(%.)abcd"
 "*d");
}

gcc accepts it, but clang rejects it:

code1.c:3:2: error: use of undeclared identifier 'u8R'
 u8R"abcd(%.)abcd"
 ^
1 error generated.

This diagnostic seems to be right?

[Bug c/86720] New: Missing symbol name in directive

2018-07-29 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86720

Bug ID: 86720
   Summary: Missing symbol name in directive
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

unsigned char foo (unsigned char x)
{
 static volatile unsigned char P1OUT __asm ("0x0021");
 unsigned char tmp = P1OUT;
 P1OUT = x;
 return tmp;
}

clang accepts the code. gcc rejects it with some strange messages:

gcc -c test.c 
/tmp/ccOWvef3.s: Assembler messages:
/tmp/ccOWvef3.s:26: Error: Missing symbol name in directive
/tmp/ccOWvef3.s:26: Error: junk at end of line, first unrecognized character is
`0'
/tmp/ccOWvef3.s:27: Error: expected symbol name

Even if the code is illegal, please refine the error messages.

[Bug c/86719] New: case label does not reduce to an integer constant

2018-07-29 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86719

Bug ID: 86719
   Summary: case label does not reduce to an integer constant
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code sample is as follow:

int main(void)
{
 const int nFOO = 1;
 int nFoo = 0;

 switch(nFoo){
 case nFOO:
 exit(1);
 }
 exit(0);
}

gcc rejects the code:

gcc code1.c 
code1.c: In function 'main':
code1.c:7:2: error: case label does not reduce to an integer constant
  case nFOO:
  ^~~~
code1.c:8:2: warning: implicit declaration of function 'exit'
[-Wimplicit-function-declaration]
  exit(1);
  ^~~~
code1.c:8:2: warning: incompatible implicit declaration of built-in function
'exit'
code1.c:8:2: note: include '' or provide a declaration of 'exit'
code1.c:1:1:
+#include 
 int main(void)
code1.c:8:2:
  exit(1);
  ^~~~
code1.c:10:2: warning: incompatible implicit declaration of built-in function
'exit'
  exit(0);
  ^~~~
code1.c:10:2: note: include '' or provide a declaration of 'exit'

The code looks legal. clang accepts it

[Bug c/86718] New: ICE during RTL pass: expand

2018-07-29 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86718

Bug ID: 86718
   Summary: ICE during RTL pass: expand
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

void __attribute__((noinline, noclone))
test(char *data, __SIZE_TYPE__ len)
{
 static char const appended[] = "/./";
 char *buf = __builtin_alloca (len + sizeof appended);
 __builtin_memcpy (buf, data, len);
 __builtin_strcpy (buf + len, [data[len - 1] == '/']);
 if (__builtin_strcmp(buf, "test1234/./"))
 __builtin_abort();
}

int
main()
{
 char *arg = "test1234/";
 test(arg, __builtin_strlen(arg));
 return 0;
}

The error messages are as follows:

gcc code5.c 
during RTL pass: expand
code5.c: In function 'test':
code5.c:7:2: internal compiler error: tree check: expected integer_cst, have
minus_expr in get_len, at tree.h:5553
  __builtin_strcpy (buf + len, [data[len - 1] == '/']);
  ^
0x717120 tree_check_failed(tree_node const*, char const*, int, char const*,
...)
../../gcc9.0/gcc/tree.c:9351
0x6226ea tree_check(tree_node const*, char const*, int, char const*, tree_code)
../../gcc9.0/gcc/tree.h:3373
0x6226ea wi::extended_tree<192>::get_len() const
../../gcc9.0/gcc/tree.h:5553
0x6226ea wi::int_traits >
>::decompose(long*, unsigned int, generic_wide_int >
const&)
../../gcc9.0/gcc/wide-int.h:961
0x6226ea wide_int_ref_storage::wide_int_ref_storage >
>(generic_wide_int > const&, unsigned int)
../../gcc9.0/gcc/wide-int.h:1010
0x6226ea generic_wide_int
>::generic_wide_int >
>(generic_wide_int > const&, unsigned int)
../../gcc9.0/gcc/wide-int.h:785
0x6226ea bool wi::lts_p >,
generic_wide_int >
>(generic_wide_int > const&,
generic_wide_int > const&)
../../gcc9.0/gcc/wide-int.h:1877
0x6226ea wi::binary_traits >,
generic_wide_int >,
wi::int_traits > >::precision_type,
wi::int_traits >
>::precision_type>::signed_predicate_result operator<
 >,
generic_wide_int >
>(generic_wide_int > const&,
generic_wide_int > const&)
../../gcc9.0/gcc/wide-int.h:3224
0x6226ea tree_int_cst_lt(tree_node const*, tree_node const*)
../../gcc9.0/gcc/tree.h:5709
0x6226ea check_access
../../gcc9.0/gcc/builtins.c:3199
0x8ac3fd expand_builtin_strcpy
../../gcc9.0/gcc/builtins.c:3816
0x8ac3fd expand_builtin(tree_node*, rtx_def*, rtx_def*, machine_mode, int)
../../gcc9.0/gcc/builtins.c:7220
0x9cfe15 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
../../gcc9.0/gcc/expr.c:10911
0x8cb478 expand_expr
../../gcc9.0/gcc/expr.h:279
0x8cb478 expand_call_stmt
../../gcc9.0/gcc/cfgexpand.c:2687
0x8cb478 expand_gimple_stmt_1
../../gcc9.0/gcc/cfgexpand.c:3575
0x8cb478 expand_gimple_stmt
../../gcc9.0/gcc/cfgexpand.c:3734
0x8cc40f expand_gimple_basic_block
../../gcc9.0/gcc/cfgexpand.c:5769
0x8d0ff7 execute
../../gcc9.0/gcc/cfgexpand.c:6372
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

[Bug c/86716] New: use of parameter outside function body before ‘++’ token

2018-07-28 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86716

Bug ID: 86716
   Summary: use of parameter outside function body before ‘++’
token
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

#include 
int
f (int a, int b[a++], int c, int d[c++])
{
 printf ("%d %d\n", a, c);
}

int
main (void)
{
 int dummy[10];
 f (1, dummy, 1, dummy);
 return 0;
}

gcc rejects the code:

gcc code0.c.cpp 
code0.c.cpp:3:18: error: use of parameter outside function body before '++'
token
 f (int a, int b[a++], int c, int d[c++])
  ^~
code0.c.cpp:3:21: error: expected ')' before ',' token
 f (int a, int b[a++], int c, int d[c++])
   ~ ^
 )
code0.c.cpp:3:23: error: expected unqualified-id before 'int'
 f (int a, int b[a++], int c, int d[c++])
   ^~~

clang accepts the code. The above code looks legal?

[Bug middle-end/86715] New: ICE passing too large argument on stack

2018-07-28 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86715

Bug ID: 86715
   Summary: ICE passing too large argument on stack
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: middle-end
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

#define COLS 24000L

struct Matrix {
  float data[COLS * COLS];
};

float mulv(float A[], float B[], int i, int j)
{
  float result = 0.0;
  { int k; for (k = 0; k < COLS; ++k)
 result += A[i*COLS + k] * B[j + k*COLS];
  }
  return result;
}

struct Matrix mulm(struct Matrix A, struct Matrix B)
{
  struct Matrix result;

#define IJ(M) (M[i*COLS + j])

  { int i, j; for (i = 0; i < COLS; ++i)
for (j = 0; j < COLS; ++j)
  IJ(result.data) = mulv(A.data, B.data, i, j);
  }
  return result;
}

int main(int argc, char* argv[])
{
  struct Matrix m1, m2, result;

  result = mulm(m1, m2);
  return result.data[argc];
}

The error messages of gcc are as follows:

2sameartificialtestprogramhopefullytextplain.cpp: In function 'int main(int,
char**)':
2sameartificialtestprogramhopefullytextplain.cpp:34:23: sorry, unimplemented:
passing too large argument on stack
   result = mulm(m1, m2);
   ^
2sameartificialtestprogramhopefullytextplain.cpp:34:23: sorry, unimplemented:
passing too large argument on stack
during RTL pass: expand
2sameartificialtestprogramhopefullytextplain.cpp:34:23: internal compiler
error: in expand_call, at calls.c:4591
0x6d26bd expand_call(tree_node*, rtx_def*, int)
../../gcc9.0/gcc/calls.c:4588
0xbdfefe expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
../../gcc9.0/gcc/expr.c:10914
0xbec31f store_expr(tree_node*, rtx_def*, int, bool, bool)
../../gcc9.0/gcc/expr.c:5614
0xbed74b expand_assignment(tree_node*, tree_node*, bool)
../../gcc9.0/gcc/expr.c:5398
0xadb8e4 expand_call_stmt
../../gcc9.0/gcc/cfgexpand.c:2685
0xadb8e4 expand_gimple_stmt_1
../../gcc9.0/gcc/cfgexpand.c:3575
0xadb8e4 expand_gimple_stmt
../../gcc9.0/gcc/cfgexpand.c:3734
0xadcc4f expand_gimple_basic_block
../../gcc9.0/gcc/cfgexpand.c:5769
0xae1837 execute
../../gcc9.0/gcc/cfgexpand.c:6372
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

My gcc is 9.0.0

[Bug c/86709] New: 'short type-name' is invalid

2018-07-27 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86709

Bug ID: 86709
   Summary: 'short type-name' is invalid
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

gcc allows ``short'' to appear with a typedef'd char:

typedef unsigned char __u8;
__u8 short slot_tablelen;

is accepted, but

unsigned char short slot_tablelen;

is not, which doesn't make sense to me.  (In C99, short is
not allowed with any typedef'd name -- I'm not sure why it's
allowed in gcc.)

My gcc is gcc version 9.0.0 20180715 (experimental) (GCC)

I tried clang++. It rejects both code samples:

error: 'short type-name' is invalid
__u8 short slot_tablelen;
 ^
1 error generated.

error: 'short char' is invalid
unsigned char short slot_tablelen;
  ^
1 error generated.

[Bug c++/86665] New: declaration conflicts with target of using declaration already in scope

2018-07-24 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86665

Bug ID: 86665
   Summary: declaration conflicts with target of using declaration
 already in scope
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

namespace Name {
 template  class Point;
}

using Name::Point;

template  class Point {
 public:
 Point() {}
 protected:
 T member;
};

int main(void) {
 Name::Point d;
 return(0);
}

g++ accepts it, but clang++ rejects it:

code2.cpp:7:20: error: declaration conflicts with target of using declaration
  already in scope
template  class Point {
   ^
code2.cpp:2:27: note: target of using declaration
 template  class Point;
  ^
code2.cpp:5:13: note: using declaration
using Name::Point;
^
code2.cpp:15:22: error: implicit instantiation of undefined template
  'Name::Point'
 Name::Point d;
 ^
code2.cpp:2:27: note: template is declared here
 template  class Point;
  ^
2 errors generated.

My g++ is gcc version 9.0.0 20180715 (experimental) (GCC), and my clang++ is  
clang version 7.0.0 (trunk 337118)

[Bug c++/86652] pointer to function type cannot have 'const' qualifier

2018-07-23 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86652

--- Comment #1 from zhonghao at pku dot org.cn ---
A related code sample:

class C { public: template int (*f())() const; };
int foo(C c) { return (*c.f())(); }

The messages from clang++:
error: pointer to function type cannot have 'const' qualifier
class C { public: template int (*f())() const; };

error: no matching member function for call to 'f'
int foo(C c) { return (*c.f())(); }
~~^~
2 errors generated.

[Bug c++/86652] New: pointer to function type cannot have 'const' qualifier

2018-07-23 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86652

Bug ID: 86652
   Summary: pointer to function type cannot have 'const' qualifier
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

class C { 
public: 
 template  
 int (*f())() const; 
};

g++ accepts the code, but clang++ rejects it:

code4.cpp:4:7: error: pointer to function type cannot have 'const' qualifier
 int (*f())() const; 
  ^
1 error generated.

If it's a pointer to a const function, the line shall be:

int (*f() const)();

If the return type is const (which is of course meaningless), the line shall
be:

const int (*f())();

However, I do not quite understant int (*f())() const;. Maybe it is illegal as
clang++ says?

[Bug c++/86633] New: invalid with rvalue references

2018-07-22 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86633

Bug ID: 86633
   Summary: invalid with rvalue references
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

int x = reinterpret_cast(1.0f);

Consensus on IRC is that this is invalid.

g++ accepts it, but clang++ rejects it:

code0.cpp:1:9: error: reinterpret_cast from rvalue to reference type
  'const int &&'
int x = reinterpret_cast(1.0f);
^~~
1 error generated.

[Bug c++/86602] New: need to check for a placeholder in argument to noexcept

2018-07-20 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86602

Bug ID: 86602
   Summary: need to check for a placeholder in argument to
noexcept
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

g++ accepts this invalid code:

void f();
void f(int);
bool b = noexcept(f);

[over.over]p1: "An overloaded function name shall not be used without arguments
in contexts other than those listed."

clang++ rejects it:

code1.cpp:3:19: error: reference to overloaded function could not be resolved;
  did you mean to call it with no arguments?
bool b = noexcept(f);
  ^
   ()
code1.cpp:2:6: note: possible target for call
void f(int);
 ^
code1.cpp:1:6: note: possible target for call
void f();
 ^
1 error generated.

[Bug c++/86601] New: g++ accepts 'friend' at ill-formed positions in the decl-specifier-seq

2018-07-20 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86601

Bug ID: 86601
   Summary: g++ accepts 'friend' at ill-formed positions in the
decl-specifier-seq
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

g++ accepts this:

  struct S {
class T friend;
unsigned friend char;
  };

Both of these are illegal by [class.friend]p3, which requires the 'friend'
decl-specifier to be the first in the decl-specifier-seq for non-function
declarations.

BTW, clang++ rejects it:

code0.cpp:2:10: error: 'friend' must appear first in a non-function declaration
 class T friend;
 ^
code0.cpp:3:11: error: 'friend' must appear first in a non-function declaration
 unsigned friend char;
  ^
2 errors generated.

[Bug c++/86600] New: Class declaration in the same declarative region as using declaration - Missing diagnostic message

2018-07-20 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86600

Bug ID: 86600
   Summary: Class declaration in the same declarative region as
using declaration - Missing diagnostic message
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The following program should give a diagnostic message when trying to compile
it.

namespace X { class A; }

namespace Y { using X::A; class A {}; }

int main() {}

This is because it violates [basic.scope.declarative]/4 in the c++ standard:

  http://eel.is/c++draft/basic.scope.declarative#4

The diagnostic message is missing. MSVS gives a diagnostic message for this
program, but clang does not.

Stack overflow post confirming the bug:

 
http://stackoverflow.com/questions/31220154/class-declaration-in-same-scope-as-using-declaration-compiles-in-gcc-but-not-msv

clang++ also gives an error message:

code0.cpp:3:27: error: declaration conflicts with target of using declaration
  already in scope
namespace Y { using X::A; class A {}; }
  ^
code0.c.cpp:1:21: note: target of using declaration
namespace X { class A; }
^
code0.c.cpp:3:24: note: using declaration
namespace Y { using X::A; class A {}; }
   ^
1 error generated.

[Bug c++/86598] New: Incorrect lexing of pp-numbers in C++11 due to hexfloat extension

2018-07-19 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86598

Bug ID: 86598
   Summary: Incorrect lexing of pp-numbers in C++11 due to
hexfloat extension
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

g++ support C99 hexadecimal literals as an extension in its C++ modes. This is
*almost* a conforming extension in C++98 mode, but it's far from being one in
C++11 mode. For instance, in C++98:

#define PREFIX(x) foo ## x
void f() {
  int PREFIX(1p);
  int PREFIX(2p) = PREFIX(1p+5);
}

g++ rejects the above code:

code2.cpp:1:19: error: pasting "foo" and "1p+5" does not give a valid
preprocessing token
 #define PREFIX(x) foo ## x
   ^~~
code2.cpp:4:19: note: in expansion of macro 'PREFIX'
  int PREFIX(2p) = PREFIX(1p+5); 
   ^~
code2.cpp: In function 'void f()':
code2.cpp:1:19: error: 'foo' was not declared in this scope
 #define PREFIX(x) foo ## x
   ^~~
code2.cpp:4:19: note: in expansion of macro 'PREFIX'
  int PREFIX(2p) = PREFIX(1p+5); 
   ^~
code2.cpp:1:19: note: suggested alternative: 'foo2p'
 #define PREFIX(x) foo ## x
   ^~~
code2.c.cpp:4:19: note: in expansion of macro 'PREFIX'
  int PREFIX(2p) = PREFIX(1p+5); 
   ^~

In the rules of C++, "1p+5" is three tokens, not one.

In C++11, this goes wrong in much less contrived situations:

Units operator"" _amp(unsigned long long d);
int k = 4_amp+1; // incorrect error: no literal operator "" _amp+1

BTW, clang++ accepts the above code.

[Bug c++/86596] New: non-type template argument evaluates to an integer

2018-07-19 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86596

Bug ID: 86596
   Summary: non-type template argument evaluates to an integer
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

template struct A {};

typedef A<255> B;

int main() { return 0; }

g++ accepts the code, but clang++ rejects it:

char.cpp:3:11: error: non-type template argument evaluates to 255, which
  cannot be narrowed to type 'char' [-Wc++11-narrowing]
typedef A<255> B;
  ^
1 error generated.


The code looks illegal, so the diagnose of clang++ is right?

[Bug c++/86594] New: Crash on trying to capture 'this' in instantiation of generic lambda

2018-07-19 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86594

Bug ID: 86594
   Summary: Crash on trying to capture 'this' in instantiation of
generic lambda
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

#include 

template 
constexpr void for_sequence(std::integer_sequence, F&& f) {
using unpack_t = int[];
(void)unpack_t{(static_cast(f(std::integral_constant{})),
0)..., 0};
}

template
struct MyType {
void crash() {
   
for_sequence(std::make_index_sequence::value>{}, [&](auto
i){
make_crash();
});
}

template
void make_crash() {}
};

int main() {
MyType> test;

test.crash();
}

g++ crashes with the following messages:

crash.cpp: In instantiation of 'MyType::crash() [with Tup =
std::tuple]:: [with auto:1 =
std::integral_constant]':
2CPPfilethattriggerthecrash.cpp:6:37:   required from 'constexpr void
for_sequence(std::integer_sequence, F&&) [with T = long unsigned int;
T ...S = {0, 1, 2, 3}; F = MyType::crash() [with Tup = std::tuple]::]'
2CPPfilethattriggerthecrash.cpp:12:15:   required from 'void
MyType::crash() [with Tup = std::tuple]'
2CPPfilethattriggerthecrash.cpp:24:13:   required from here
2CPPfilethattriggerthecrash.cpp:13:4: internal compiler error: trying to
capture 'this' in instantiation of generic lambda
make_crash();
^~
0x90c905 add_capture(tree_node*, tree_node*, tree_node*, bool, bool)
../../gcc9.0/gcc/cp/lambda.c:648
0x90ca5e add_default_capture(tree_node*, tree_node*, tree_node*)
../../gcc9.0/gcc/cp/lambda.c:714
0x90cf01 lambda_expr_this_capture(tree_node*, bool)
../../gcc9.0/gcc/cp/lambda.c:819
0x90d670 maybe_resolve_dummy(tree_node*, bool)
../../gcc9.0/gcc/cp/lambda.c:902
0x85762a build_new_method_call_1
../../gcc9.0/gcc/cp/call.c:9416
0x85762a build_new_method_call(tree_node*, tree_node*, vec**, tree_node*, int, tree_node**, int)
../../gcc9.0/gcc/cp/call.c:9531
0x9adcb8 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
../../gcc9.0/gcc/cp/pt.c:18491
0x991329 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
../../gcc9.0/gcc/cp/pt.c:17431
0x99166d tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
../../gcc9.0/gcc/cp/pt.c:16630
0x991390 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
../../gcc9.0/gcc/cp/pt.c:16915
0x991390 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
../../gcc9.0/gcc/cp/pt.c:16915
0x991390 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
../../gcc9.0/gcc/cp/pt.c:16915
0x9bf24e tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
../../gcc9.0/gcc/cp/pt.c:16601
0x9bf24e instantiate_decl(tree_node*, bool, bool)
../../gcc9.0/gcc/cp/pt.c:24075
0x8e603b maybe_instantiate_decl
../../gcc9.0/gcc/cp/decl2.c:5173
0x8e8167 mark_used(tree_node*, int)
../../gcc9.0/gcc/cp/decl2.c:5323
0x854e8e build_over_call
../../gcc9.0/gcc/cp/call.c:8325
0x862b2a build_op_call_1
../../gcc9.0/gcc/cp/call.c:4602
0x862b2a build_op_call(tree_node*, vec**, int)
../../gcc9.0/gcc/cp/call.c:4631
0x9d95ad finish_call_expr(tree_node*, vec**, bool,
bool, int)
../../gcc9.0/gcc/cp/semantics.c:2553
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

[Bug c++/86583] New: exception specification of explicitly defaulted destructor does not match the calculated one

2018-07-18 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86583

Bug ID: 86583
   Summary: exception specification of explicitly defaulted
destructor does not match the calculated one
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

struct T {
T() noexcept(false) { }
~T() noexcept(false) { }
};

struct A
{
A() noexcept = default;
~A() noexcept = default;

T t;
};

g++ accepts the code, but I think it shouldn't be.

In fact, g++4.9.0 rejects the code:

ex.cc:8:5: error: function 'A::A()' defaulted on its first declaration with an
exception-specification that differs from the implicit declaration 'A::A()'
 A() noexcept = default;
 ^
ex.cc:9:5: error: function 'A::~A()' defaulted on its first declaration with an
exception-specification that differs from the implicit declaration 'A::~A()'
 ~A() noexcept = default; 


I tried clang++. It also rejects the code:

ex.cc:8:2: error: exception specification of explicitly defaulted default
  constructor does not match the calculated one
 A() noexcept = default;
 ^
ex.cc:9:2: error: exception specification of explicitly defaulted
  destructor does not match the calculated one
 ~A() noexcept = default;
 ^
2 errors generated.

[Bug c++/86581] New: constexpr variable is not checked

2018-07-18 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86581

Bug ID: 86581
   Summary: constexpr variable is not checked
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

template struct V {
 union { int n; struct { int x,y; }; };

 constexpr V() : x(0) {} 
}; 
constexpr V v;

g++ does not check whether v is initialized. Instead, clang++ does that:

code0.cpp:6:18: error: constexpr variable 'v' must be initialized by a
  constant expression
constexpr V v;
 ^
code0.cpp:6:18: note: subobject of type 'int' is not initialized
1 error generated.

[Bug c++/86580] New: No warning for default arguments

2018-07-18 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86580

Bug ID: 86580
   Summary: No warning for default arguments
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

struct S { S(const S&, int); S(int); }; S::S(const S& = S(0), int = 0) {}

g++ accepts without any warning messages. Instead, clang++ reports:

code0.cpp:1:55: error: addition of default argument on redeclaration makes
  this constructor a default constructor
struct S { S(const S&, int); S(int); }; S::S(const S& = S(0), int = 0) {}
  ^ 
code0.cpp:1:12: note: previous declaration is here
struct S { S(const S&, int); S(int); }; S::S(const S& = S(0), int = 0) {}
   ^
1 error generated.

[Bug c++/86579] New: invalid operands to binary expression

2018-07-18 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86579

Bug ID: 86579
   Summary: invalid operands to binary expression
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

template 
bool greater()
{
 T p = nullptr;
 return p > nullptr;
}

int main ()
{
 greater();
}

g++ accepts it, but clang++ reports a error message:

code0.cpp:5:11: error: invalid operands to binary expression ('void *' and
  'nullptr_t')
 return p > nullptr;
~ ^ ~~~
code0.cpp:10:2: note: in instantiation of function template specialization
  'greater' requested here
 greater();
 ^
1 error generated.

[Bug c++/86578] New: requested alignment is dependent but declaration is not dependent

2018-07-18 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86578

Bug ID: 86578
   Summary: requested alignment is dependent but declaration is
not dependent
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

template  void Fun(T A) {
 typedef int __attribute__((__aligned__(A))) T1;
 int k1[__alignof__(T1)];
}

g++ accepts it, but clang++ rejects it:

code0.cpp:2:29: error: requested alignment is dependent but declaration is not
dependent
 typedef int __attribute__((__aligned__(A))) T1;
^   ~
1 error generated.

[Bug c++/86577] New: non-ADL name lookup for operator<< at instantiation time?

2018-07-18 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86577

Bug ID: 86577
   Summary: non-ADL name lookup for operator<< at instantiation
time?
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

#include 

 namespace N {
 struct X { };
 }
 using namespace N;

 template
 void log(const T& t) {
 std::clog << t;
 } 

 std::ostream <<(std::ostream&, const X& x);

 template void log(const X&);


g++ accepts the code, but clang++ rejects it:

code0.cpp:10:12: error: call to function 'operator<<' that is neither visible
  in the template definition nor found by argument-dependent lookup
 std::clog << t;
   ^
code0.cpp:15:16: note: in instantiation of function template specialization
  'log' requested here
 template void log(const X&);
   ^
code0.cpp:13:16: note: 'operator<<' should be declared prior to the call site
  or in namespace 'N'
 std::ostream <<(std::ostream&, const X& x);
   ^
1 error generated.

Does g++ perform non-ADL name lookup for operator<< at instantiation time? This
sounds incorrect.

[Bug c++/86565] New: failing to instantiate all of a local class

2018-07-17 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86565

Bug ID: 86565
   Summary: failing to instantiate all of a local class
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

template void f() {
 struct S { void g(int n = T::error) noexcept(T::error); };
}
template void f();

g++ accepts it, but clang++ rejects it:

code0.cpp:2:28: error: type 'int' cannot be used prior to '::' because it has
  no members
 struct S { void g(int n = T::error) noexcept(T::error); };
   ^
code0.cpp:2:9: note: in instantiation of member class 'S' requested here
 struct S { void g(int n = T::error) noexcept(T::error); };
^
code0.cpp:4:15: note: in instantiation of function template specialization
  'f' requested here
template void f();
  ^
code0.cpp:2:47: error: type 'int' cannot be used prior to '::' because it has
  no members
 struct S { void g(int n = T::error) noexcept(T::error); };
  ^
2 errors generated.


g++ should reject this, because instantiating a function is supposed to
instantiate everything within the function, even pieces of a local class.

(Incidentally, failing to do this can lead to the "decl not instantiated in
this scope" assertion.)

[Bug c++/86564] New: Declaration containing qualified-id interpreted as function-style cast

2018-07-17 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86564

Bug ID: 86564
   Summary: Declaration containing qualified-id interpreted as
function-style cast
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

 struct foo {
 static bool const value = false;
 };

 int main() {
 int v(int(foo::value));
 }

g++ accepts it, but clang++ rejects it:

code0.cpp:6:17: error: parameter declarator cannot be qualified
 int v(int(foo::value));
   ~^
code0.cpp:6:7: warning: parentheses were disambiguated as a function
  declaration [-Wvexing-parse]
 int v(int(foo::value));
  ^
code0.cpp:6:8: note: add a pair of parentheses to declare a variable
 int v(int(foo::value));
   ^
   (  )
1 warning and 1 error generated.

The paragraphs in the C++ Standard, 6.8 and 8.2 say that disambiguation is
purely syntactic, and any construct that could be a declaration is taken and
parsed as a declaration. The grammar of C++ allows a declarator-id be a
qualified-id, which makes for the following be a well-formed construct

struct foo {
  static int value;
};

int (foo::value);

Thus, the function declaration in main above would contain a parameter whose
name is a qualified-id. This is ill-formed and should be rejected.

[Bug c++/86563] New: catch reference to incomplete type

2018-07-17 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86563

Bug ID: 86563
   Summary: catch reference to incomplete type
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

struct T;

template 
void f()
{
 try
 {}
 catch(T const &)
 {}
}

struct T
{};

int main()
{
 f();
 return 0;
}

g++ accepts, but clang++ rejects it:

code0.cpp:8:17: error: cannot catch reference to incomplete type 'const T'
 catch(T const &)
^
code0.cpp:1:8: note: forward declaration of 'T'
struct T;
   ^
1 error generated.


15.3 Handling an exception [except.handle]

1 The exception-declaration in a handler describes the type(s) of exceptions
that can cause that handler to be entered. The exception-declaration shall not
denote an incomplete type or an rvalue reference type. The
exception-declaration shall not denote a pointer or reference to an incomplete
type, other than void*, const void*, volatile void*, or const volatile void*.

[Bug c++/86562] New: Missing warning (error in C++11) for passing nontrivial object to varargs function via function pointer

2018-07-17 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86562

Bug ID: 86562
   Summary: Missing warning (error in C++11) for passing
nontrivial object to varargs function via function
pointer
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

struct Foo {
 Foo() {}
 Foo(const Foo&) {}
};

void f(...);

void g() {
 Foo foo;
 f(foo);
 void (*fp)(...) = f;
 fp(foo);
}

g++ accepts it, but clang++ rejects it:



code1.cpp:10:4: error: cannot pass object of non-trivial type 'Foo' through
  variadic function; call will abort at runtime [-Wnon-pod-varargs]
 f(foo);
   ^
code1.cpp:12:5: error: cannot pass object of non-trivial type 'Foo' through
  variadic function; call will abort at runtime [-Wnon-pod-varargs]
 fp(foo);
^
2 errors generated.

[Bug c++/86561] New: a function definition must occur in a standalone declaration

2018-07-17 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86561

Bug ID: 86561
   Summary: a function definition must occur in a standalone
declaration
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

struct S { int f(), g() = delete; };

g++ accepts the code, but clang++ rejects it:

error: '= delete' is a function definition and must occur in a
  standalone declaration
struct S { int f(), g() = delete; };
  ^
1 error generated.

[Bug c++/86558] New: ICE on template code

2018-07-17 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86558

Bug ID: 86558
   Summary: ICE on template code
   Product: gcc
   Version: 9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

template  struct VI {};
template 
struct IP
{
 static const bool r = IP::r;
};
template  struct V
{
 VI::r> vi;
};
struct X;
struct Y
{
 V v;
};

g++ produces the following messages:

code0.cpp: In instantiation of 'const bool IP::r':
code0.cpp:5:20:   recursively required from 'const bool IP::r'
code0.cpp:5:20:   required from 'const bool IP::r'
code0.cpp:9:15:   required from 'struct V'
code0.cpp:14:7:   required from here
code0.cpp:5:20: fatal error: template instantiation depth exceeds maximum of
900 (use -ftemplate-depth= to increase the maximum)
  static const bool r = IP::r;
^
compilation terminated.

I increased the depth: g++ -ftemplate-depth=10 code0.cpp 
This time, I got an ICE:

g++: internal compiler error: Segmentation fault signal terminated program
cc1plus
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
root@haozhong-Precision-Tower-7910:/home/haozhong/project/approach/otherreport/g
cc/tmp/gcc_50436# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc9.0/configure --enable-languages=c,c++
--disable-multilib
Thread model: posix
gcc version 9.0.0 20180715 (experimental) (GCC)

[Bug c++/86503] New: Segmentation fault signal terminated

2018-07-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86503

Bug ID: 86503
   Summary: Segmentation fault signal terminated
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

template< bool c, class T >
struct enable_if {
typedef T type;
};

template< class T >
struct enable_if< true, T > {};

template< class F, int n >
void
ft( F f, typename enable_if< n == 0, int >::type ) {}

template< class F, int n >
typeof( ft< F, n-1 >( F(), 0 ) )
ft( F f, typename enable_if< n != 0, int >::type ) {}

int main() {
ft< struct a*, 2 >( 0, 0 );
}

g++ produces the following error message:

3regressiontestusingG++typeof.cpp: In substitution of 'template
__typeof__ (ft(F(), 0)) ft(F, typename enable_if<(n != 0),
int>::type) [with F = main()::a*; int n = -897]':
3regressiontestusingG++typeof.cpp:14:21:   recursively required by substitution
of 'template __typeof__ (ft(F(), 0)) ft(F, typename
enable_if<(n != 0), int>::type) [with F = main()::a*; int n = 1]'
3regressiontestusingG++typeof.cpp:14:21:   required by substitution of
'template __typeof__ (ft(F(), 0)) ft(F, typename
enable_if<(n != 0), int>::type) [with F = main()::a*; int n = 2]'
3regressiontestusingG++typeof.cpp:18:30:   required from here
3regressiontestusingG++typeof.cpp:14:21: fatal error: template instantiation
depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum)
 typeof( ft< F, n-1 >( F(), 0 ) )
   ~~^~~~
compilation terminated.

So, I change the command line to:
g++ -ftemplate-depth=100 3regressiontestusingG++typeof.cpp 

This time, the error message is as follow:

g++: internal compiler error: Segmentation fault signal terminated program
cc1plus
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

Anyway, clang++ accepts the code.

[Bug c++/86502] New: friend declaration specifying a default argument must be a definition

2018-07-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86502

Bug ID: 86502
   Summary: friend declaration specifying a default argument must
be a definition
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

class Test
{
 friend const int getInt(int inInt = 0);
};


g++ accepts it, but clang++ rejects it:

error: friend declaration specifying a default argument must be a definition

[Bug c++/86501] New: shadow template parameter

2018-07-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86501

Bug ID: 86501
   Summary: shadow template parameter
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

template < int V >
struct A
{ 
 struct B
 { 
 template < int > friend struct V; 
 };
};

A < 0 >::B a;

g++ accepts the code, but clang++ rejects it:

error: declaration of 'V' shadows template parameter
 template < int > friend struct V; 
^
note: template parameter is declared here
template < int V >
   ^
1 error generated.

[Bug c++/86500] New: accepts-invalid with :: before decltype

2018-07-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86500

Bug ID: 86500
   Summary: accepts-invalid with :: before decltype
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

g++ incorrectly accepts this:

struct S { struct T {}; };
::decltype(S())::T st;

clang++ rejects it:

error: expected unqualified-id

[Bug c++/86499] New: lambda-expressions with capture-default are allowed at namespace scope

2018-07-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86499

Bug ID: 86499
   Summary: lambda-expressions with capture-default are allowed at
namespace scope
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

g++ incorrectly accepts this:

  auto l = [=]{};

Per C++1y [expr.lambda]p9 this is ill-formed: only local lambda expressions may
have capture-defaults (even if they don't actually capture anything).

[Bug c++/86498] New: g++ allows conversion from string literal to non-const char* in C++11 mode

2018-07-11 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86498

Bug ID: 86498
   Summary: g++ allows conversion from string literal to non-const
char* in C++11 mode
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

g++ rejects this valid C++11 code:

  void f(char*);
  int (...);
  int  = f("foo");

There is no conversion from string literal to non-const char* in C++11.

[Bug c++/86478] New: Crashed on legal code

2018-07-10 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86478

Bug ID: 86478
   Summary: Crashed on legal code
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

template
struct X
{};

template
void foo(X... a);

void test()
{
 foo(X(), X());
}

g++ crashes when compiling the code:

code0.cpp: In substitution of 'template void foo(X...)
[with T = ]':
code0.cpp:10:53:   required from here
code0.cpp:10:53: internal compiler error: tree check: expected class
'expression', have 'type' (integer_type) in tree_operand_check, at tree.h:3633
  foo(X(), X());
 ^
0x79b1a2 tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
../../code/gcc/tree.c:9377
0x65b01a expr_check(tree_node*, char const*, int, char const*)
../../code/gcc/tree.h:3304
0x65b01a tree_operand_check(tree_node*, int, char const*, int, char const*)
../../code/gcc/tree.h:3633
0x65b01a unify_pack_expansion
../../code/gcc/cp/pt.c:20777
0x990032 unify
../../code/gcc/cp/pt.c:21565
0x98edf3 unify
../../code/gcc/cp/pt.c:21762
0x98fe10 unify
../../code/gcc/cp/pt.c:21559
0x98e8a2 try_class_unification
../../code/gcc/cp/pt.c:20559
0x990925 unify
../../code/gcc/cp/pt.c:21596
0x9958a3 unify_one_argument
../../code/gcc/cp/pt.c:19793
0x996520 unify_pack_expansion
../../code/gcc/cp/pt.c:20808
0x997ab6 type_unification_real
../../code/gcc/cp/pt.c:19933
0x998ab5 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, bool, bool)
../../code/gcc/cp/pt.c:19298
0x839f0f add_template_candidate_real
../../code/gcc/cp/call.c:3179
0x83a920 add_template_candidate
../../code/gcc/cp/call.c:3258
0x83a920 add_candidates
../../code/gcc/cp/call.c:5520
0x83ad31 add_candidates
../../code/gcc/cp/call.c:4192
0x83ad31 perform_overload_resolution
../../code/gcc/cp/call.c:4200
0x83cda2 build_new_function_call(tree_node*, vec**, int)
../../code/gcc/cp/call.c:4273
0x9bb475 finish_call_expr(tree_node*, vec**, bool,
bool, int)
../../code/gcc/cp/semantics.c:2534
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Clang++ accepts the above code.

[Bug c++/86477] New: failure binding reference to vector element

2018-07-10 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86477

Bug ID: 86477
   Summary: failure binding reference to vector element
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

typedef __attribute__((ext_vector_type(4))) int vi4;
const int  = vi4(1).x;

g++ rejects it:

error: request for member 'x' in '1', which is of non-class type 'vi4' {aka
'int'}
 const int  = vi4(1).x;

clang++ accepts the code. It looks like well-formed, right?

[Bug c++/86476] New: Members declared later in a class appear to be unavailable

2018-07-10 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86476

Bug ID: 86476
   Summary: Members declared later in a class appear to be
unavailable
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

template 
struct A {
  void f() noexcept(noexcept(m.f())) {
m.f();
  }
  T m;
};
struct B { void f(); };
int main() {
  A a;
  a.f();
}

g++ produces:
 error: 'm' was not declared in this scope
  void f() noexcept(noexcept(m.f())) {


What gives? Surely A is complete in this context and we can see m?

I tried clang++. It accepts the code.

[Bug c++/86475] New: CWG 1550

2018-07-10 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86475

Bug ID: 86475
   Summary: CWG 1550
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

I looked around to see if a bug was already filed on this and couldn't find
one.

CWG 1550, passed in Bristol, changes the value category of the result of a
conditional operator when one operand is an lvalue and the other is a
throw-expression:

* The second or the third operand (but not both) is a (possibly parenthesized)
throw-expression (15.1); the result is of the type and value category of the
other.

Here is a test, that should compile in C++:

struct X
{
int i_;
bool b_;

int& test() {return b_ ? i_ : throw 1;}
};

Current behavior is:

 error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of
type 'int'
  int& test() {return b_ ? i_ : throw 1;}
  ~~~^~

^
1 error generated.

I tried clang++. It accepts the code.

[Bug c++/86474] New: a problem in member lookup?

2018-07-10 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86474

Bug ID: 86474
   Summary: a problem in member lookup?
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

namespace PR5820 {
struct Base {};
struct D1 : public Base {};
struct D2 : public Base {};

struct Derived : public D1, public D2 {
 void Inner() {
 }
};
}

template
struct BaseT {
 int Member;
};

template struct Derived1T : BaseT { };
template struct Derived2T : BaseT { };

template
struct DerivedT : public Derived1T, public Derived2T {
 void Inner();
};

template
void Test(DerivedT d) {
 d.template Derived2T::Member = 17;
}

template void Test(DerivedT);

-

g++ rejects the code:

code0.cpp: In function 'void Test(DerivedT)':
code0.cpp:27:25: error: expected ';' before '::' token
  d.template Derived2T::Member = 17;
 ^~
 ;
code0.cpp: In instantiation of 'void Test(DerivedT) [with T = int]':
code0.cpp:30:33:   required from here
code0.cpp:27:13: error: 'Derived2T' is not a member template function
  d.template Derived2T::Member = 17;
  ~~~^~~~

This code looks legal for me. Clang++ accepts the code.

[Bug c++/86473] New: a problem in member lookup?

2018-07-10 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86473

Bug ID: 86473
   Summary: a problem in member lookup?
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

namespace PR5820 {
struct Base {};
struct D1 : public Base {};
struct D2 : public Base {};

struct Derived : public D1, public D2 {
 void Inner() {
 }
};
}

template
struct BaseT {
 int Member;
};

template struct Derived1T : BaseT { };
template struct Derived2T : BaseT { };

template
struct DerivedT : public Derived1T, public Derived2T {
 void Inner();
};

template
void Test(DerivedT d) {
 d.template Derived2T::Member = 17;
}

template void Test(DerivedT);

-

g++ rejects the code:

code0.cpp: In function 'void Test(DerivedT)':
code0.cpp:27:25: error: expected ';' before '::' token
  d.template Derived2T::Member = 17;
 ^~
 ;
code0.cpp: In instantiation of 'void Test(DerivedT) [with T = int]':
code0.cpp:30:33:   required from here
code0.cpp:27:13: error: 'Derived2T' is not a member template function
  d.template Derived2T::Member = 17;
  ~~~^~~~

This code looks legal for me. Clang++ accepts the code.

[Bug c++/86431] New: Legal code?

2018-07-06 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86431

Bug ID: 86431
   Summary: Legal code?
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

 struct A { 
 static int const B = sizeof B; 
 };

g++ rejects the code:

error: 'B' was not declared in this scope
  static int const B = sizeof B;

The PoD should should be immediately after "B" and before the initializer, as
far as I can see, so this is valid code. BTW, clang++ accepts the code.

[Bug c++/86430] New: ambiguous overload?

2018-07-06 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86430

Bug ID: 86430
   Summary: ambiguous overload?
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

// snip
template
struct Const { typedef void const type; };

template
void f(T, typename Const::type*) { } // T1

template
void f(T, void const *) {  } // T2

int main() { void *p = 0; f(0, p); }
// snap

g++ produces the following errors:

error: call of overloaded 'f(int, void*&)' is ambiguous
 int main() { void *p = 0; f(0, p); }

I tried clang++. It accepts the above code. My understanding is as follows:

template
void f(T, typename Const::type*) // T1

template
void f(T, void const *) // T2

We're going to deduce  

(unique-1, Const::type*) -> 
(T,void const*) // T1 -> T2

and

(unique-1, void const*) -> 
(T,Const::type*) // T2 -> T1

The first one takes T = unique-1 but fails at matching "void const*" to
"Const::type*". So this round fails for the second parameter. 

The second one takes T = unique-1. The second is a non-deduced context, thus
not compared, and this does not mismatch. So this round succeeds for parameter
2.

So we have: For parameter 1, each template is at least as specialized as the
other one. For parameter 2, T1 -> T2 did not succeed, so T1 is not at least as
specialized as T2 - but not vice versa (T2 -> T1 suceeded). Thus for parameter
2, T2 is more specialized.

It follows that T2 overall is more specialized that T1.

As a result, the overload is not ambiguous. Please correct me, if I am wrong.

[Bug c++/86385] New: calling wrong constructors?

2018-07-03 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86385

Bug ID: 86385
   Summary: calling wrong constructors?
   Product: gcc
   Version: 8.0.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

struct A {
 int* a;
 A(int a) : a(new int(a)) {}
 ~A() { delete a; }

 A(const A&) = delete;
 A(A&& other) { a = other.a; other.a = 0; };

 operator bool() { return true; }
 int operator*() { return *a; }
};

static A makeA(int x) { return A(x); }

int main() {
 A c = makeA(42) ?: makeA(-1);
 return *c;
}

g++ error:

error: lvalue required as unary '&' operand
  A c = makeA(42) ?: makeA(-1);

It seems that g++ considers 42 and -1 as const A& or A&& other, instead of
integer values. Or else, it does not produce such a message. I tried clang++.
It accepts the code. For me, the results of clang++ are more reasonable.

[Bug c++/86384] New: Scoped enumeration instantiated even if not required

2018-07-03 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86384

Bug ID: 86384
   Summary: Scoped enumeration instantiated even if not required
   Product: gcc
   Version: 8.0.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

template
struct A {
 enum class B {
 X = T::value
 };
};

int main() {
 A a;
}


g++ error:

code0.c.cpp:4:13: error: 'value' is not a member of 'int'
  enum class B {
 ^

This code looks well-formed. Only if we look into the enumeration, as
"A::B::X", the definition of the enumeration is required to exist and thus
implicitly instantiated. This is specified at 14.7.1p1 and p2. I tried clang++.
It accepts the code without any error message.

[Bug c++/86306] Initializing atomic qualified type with another atomic qualified type leads to assertion failure

2018-06-25 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86306

--- Comment #9 from zhonghao at pku dot org.cn ---
(In reply to zhonghao from comment #8)
> (In reply to Jonathan Wakely from comment #7)
> > (In reply to Jonathan Wakely from comment #6)
> > > Because you are just blindly copying things from one bugzilla to the 
> > > other,
> > > without making any effort to check if what you are reporting is sensible.
> > 
> > For example, in Bug 86305 you said that g++ segfaults on the code. That's
> > complete nonsense. You just took the title of the clang bug and changed
> > "clang" to "g++" even though g++ does not segfault on the code.
> > 
> > Do you really think that is helpful?
> 
> As I said, I posted the original bug reports, hoping that they can provide
> insights on why the recent gcc and clang handle the same piece of code
> differently. Sometimes, I reuse the titles of the original bug reports, so I
> can keep the links between them easier. If the titles are confusing, I will
> try to use more informative titles. However, do the differences themselves
> often reveal bugs? Furthermore, those code samples are not randomly
> generated, and they come from your real users! They are not invented by me,
> and they are real code!

Your potential users report those code samples to your competitors, so your
competitors can provide compilers of higher quality. I “steal” those code
samples to you. I thought that you must appreciate me, but you threaten to ban
me, intead. :(

[Bug c++/86306] Initializing atomic qualified type with another atomic qualified type leads to assertion failure

2018-06-25 Thread zhonghao at pku dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86306

--- Comment #8 from zhonghao at pku dot org.cn ---
(In reply to Jonathan Wakely from comment #7)
> (In reply to Jonathan Wakely from comment #6)
> > Because you are just blindly copying things from one bugzilla to the other,
> > without making any effort to check if what you are reporting is sensible.
> 
> For example, in Bug 86305 you said that g++ segfaults on the code. That's
> complete nonsense. You just took the title of the clang bug and changed
> "clang" to "g++" even though g++ does not segfault on the code.
> 
> Do you really think that is helpful?

As I said, I posted the original bug reports, hoping that they can provide
insights on why the recent gcc and clang handle the same piece of code
differently. Sometimes, I reuse the titles of the original bug reports, so I
can keep the links between them easier. If the titles are confusing, I will try
to use more informative titles. However, do the differences themselves often
reveal bugs? Furthermore, those code samples are not randomly generated, and
they come from your real users! They are not invented by me, and they are real
code!

  1   2   >