[Bug c++/102637] New: "Error: ‘reinterpret_cast’ is not a constant expression" when no reinterpret_cast is involved

2021-10-07 Thread officesamurai at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102637

Bug ID: 102637
   Summary: "Error: ‘reinterpret_cast’ is not a constant
expression" when no reinterpret_cast is involved
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

Here I obtain a function pointer to the same member function two times, through
the base and through the derived class. Then I try to compare the pointers in a
constexpr context and it fails with the error "‘reinterpret_cast’ is not a
constant expression". The same happens when I try to static_cast each pointer
to the opposite type.

gcc_constexpr_funcptr_issue.cpp:
===
struct B1
{
void foo(int) {}
};

struct B2
{
void foo(bool) {}
};

struct D: B1
#ifndef ONE_BASE
, B2
#endif
{
using B1::foo;
#ifndef ONE_BASE
using B2::foo;
#endif
};

template 
constexpr auto select(void (Class::*func)(Param))
{
return func;
}

int main()
{
constexpr auto bFunc = select(&B1::foo);
constexpr auto dFunc = select(&D::foo);

static_assert(bFunc == dFunc, "");

constexpr auto bFuncCastToDFunc = static_cast(bFunc);
constexpr auto dFuncCastToBFunc = static_cast(dFunc);
}
===

Compiler invocation:
===
$ g++-11.2.0 -c gcc_constexpr_funcptr_issue.cpp
gcc_constexpr_funcptr_issue.cpp: In function ‘int main()’:
gcc_constexpr_funcptr_issue.cpp:33:25: error: non-constant condition for static
assertion
   33 | static_assert(bFunc == dFunc, "");
  |   ~~^~~~
gcc_constexpr_funcptr_issue.cpp:33:28: error: ‘reinterpret_cast’ is not a
constant expression
   33 | static_assert(bFunc == dFunc, "");
  |^
gcc_constexpr_funcptr_issue.cpp:35:39: error: ‘reinterpret_cast’ is not a
constant expression
   35 | constexpr auto bFuncCastToDFunc = static_cast(bFunc);
  |  
^~~~
gcc_constexpr_funcptr_issue.cpp:36:39: error: ‘reinterpret_cast’ is not a
constant expression
   36 | constexpr auto dFuncCastToBFunc = static_cast(dFunc);
  |  
^
===

Additionally, if D has only one base, the call select(&D::foo) also
fails:
---
$ g++-11.2.0 -DONE_BASE -c gcc_constexpr_funcptr_issue.cpp
gcc_constexpr_funcptr_issue.cpp: In function ‘int main()’:
gcc_constexpr_funcptr_issue.cpp:31:42: error: ‘reinterpret_cast’ is not a
constant expression
   31 | constexpr auto dFunc = select(&D::foo);
  |~~^

===

Finally, even if I replace the definitions of bFunc and dFunc with
constexpr auto bFunc = &B1::foo;
constexpr auto dFunc = &D::foo;
and use -DONE_BASE, one of the casts still fails:
===
$ g++-11.2.0 -DONE_BASE -c gcc_constexpr_funcptr_issue.cpp
gcc_constexpr_funcptr_issue.cpp: In function ‘int main()’:
gcc_constexpr_funcptr_issue.cpp:35:39: error: ‘reinterpret_cast’ is not a
constant expression
   35 | constexpr auto bFuncCastToDFunc = static_cast(bFunc);
  |  
^~~~
===

Compiler info:
===
$ g++-11.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-11.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-11.2.0
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC) 
===

[Bug c++/101904] Wrong result of decltype during instantiation of std::result_of

2021-08-15 Thread officesamurai at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101904

--- Comment #2 from Mikhail Kremniov  ---
I see, thanks.
But I must mention that Clang is able to compile this code somehow.

[Bug c++/101904] New: Wrong result of decltype during instantiation of std::result_of

2021-08-13 Thread officesamurai at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101904

Bug ID: 101904
   Summary: Wrong result of decltype during instantiation of
std::result_of
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

gcc_wrong_decltype.cpp:
---
#include 

struct ZZZ
{
template 
auto foo(Func func) -> std::result_of_t
{
return func(static_cast(nullptr));
}

template 
auto foo(Func func) const -> std::result_of_t
{
return func(static_cast(nullptr));
}
};

int main()
{
const ZZZ zzz;

zzz.foo(
[&](auto* pointer)
// specifying the return type explicitly will fix the issue
//-> void
{
static_assert(std::is_same_v, "");
});
}
---

Compiler invocation:
---
$ g++-11.2.0 -c gcc_wrong_decltype.cpp 
gcc_wrong_decltype.cpp: In instantiation of ‘main():: [with
auto:1 = int]’:
/home/brd/soft/gcc-11.2.0/include/c++/11.2.0/type_traits:2466:26:   required by
substitution of ‘template static
std::__result_of_success()((declval<_Args>)()...)),
std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn =
main()::; _Args = {int*}]’
/home/brd/soft/gcc-11.2.0/include/c++/11.2.0/type_traits:2477:55:   required
from ‘struct std::__result_of_impl,
int*>’
/home/brd/soft/gcc-11.2.0/include/c++/11.2.0/type_traits:2482:12:   required
from ‘struct std::__invoke_result, int*>’
/home/brd/soft/gcc-11.2.0/include/c++/11.2.0/type_traits:2495:12:   required
from ‘struct std::result_of(int*)>’
/home/brd/soft/gcc-11.2.0/include/c++/11.2.0/type_traits:2530:11:   required by
substitution of ‘template using result_of_t = typename
std::result_of::type [with _Tp = main()::(int*)]’
gcc_wrong_decltype.cpp:6:10:   required by substitution of ‘template std::result_of_t ZZZ::foo(Func) [with Func =
main()::]’
gcc_wrong_decltype.cpp:22:12:   required from here
gcc_wrong_decltype.cpp:27:32: error: static assertion failed
   27 | static_assert(std::is_same_v, "");
  |   ~^~~~
gcc_wrong_decltype.cpp:27:32: note: ‘std::is_same_v’
evaluates to false
---

Note that 'pointer' actually points to const int (it's impossible to modify the
pointee). Also, explicitly specifying the return type for the lambda fixes the
issue.

Compiler version:
---
g++-11.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-11.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-11.2.0
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC) 
---

But the same happens with 10.3.0

[Bug c++/101901] New: "warning: statement has no effect" in a variadic template with empty parameter pack.

2021-08-13 Thread officesamurai at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101901

Bug ID: 101901
   Summary: "warning: statement has no effect" in a variadic
template with empty parameter pack.
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

gcc_statement_has_no_effect.cpp:
---
#include 

template 
void foo(const T*, int);

template 
std::string bar(T);

template 
void callFoo(T... t)
{
const std::string array[] = {bar(t)...};
foo(array, sizeof...(t));
}

void test()
{
callFoo();
}
---

Compiler invocation:
---
$ g++-11.2.0 -c gcc_statement_has_no_effect.cpp -Wunused-value
gcc_statement_has_no_effect.cpp: In instantiation of ‘void callFoo(T ...) [with
T = {}]’:
gcc_statement_has_no_effect.cpp:18:12:   required from here
gcc_statement_has_no_effect.cpp:12:23: warning: statement has no effect
[-Wunused-value]
   12 | const std::string array[] = {bar(t)...};
  |   ^
---

Technically, the compiler is correct of course, but the warning is rather
annoying, because it forces the programmer to explicitly handle this specific
case.
Also, GCC 10.3.0 doesn't produce the warning in this case.

Compiler version:
---
$ g++-11.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-11.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-11.2.0
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC) 
---

[Bug c++/97049] New: Cryptic warning "__builtin_memmove pointer overflow between offset ... and size ..." with -m32

2020-09-14 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97049

Bug ID: 97049
   Summary: Cryptic warning "__builtin_memmove pointer overflow
between offset ... and size ..." with -m32
   Product: gcc
   Version: 10.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

Created attachment 49216
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49216&action=edit
The code in question

This looks similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92879 but
this one needs -m32 to reproduce. Also, the warning message doesn't mention the
offending line number which makes it particularly cryptic.

-
$ g++-10.2.0 -O2 -m32 -c gcc10_builtin_memmove_exceeds_maximum_obj_size.cpp
In function ‘void foo()’:
cc1plus: warning: ‘void* __builtin_memmove(void*, const void*, unsigned int)’
specified bound 4294967288 exceeds maximum object size 2147483647
[]8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-overflow=-Wstringop-overflow=]8;;]
-

With -Wno-stringop-overflow -Wall another warning is produced:

-
$ g++-10.2.0 -O2 -m32 -c gcc10_builtin_memmove_exceeds_maximum_obj_size.cpp
-Wno-stringop-overflow -Wall
In function ‘void foo()’:
cc1plus: warning: ‘void* __builtin_memmove(void*, const void*, unsigned int)’
pointer overflow between offset [0, 1073741831] and size 4294967288
[]8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Warray-bounds-Warray-bounds]8;;]
-

Interestingly, if I change the type of 'size' on the line 116 to 'int', the
warnings go away.


The compiler:
-
$ g++-10.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-10.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-10.2.0/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-10.2.0
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC) 

-

[Bug target/97025] In -m32 mode the alignment of pointers returned by malloc or operator new is less than alignof(std::max_align_t)

2020-09-13 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97025

--- Comment #5 from Mikhail Kremniov  ---
I see. So this is not considered a bug then?

P.S. it seems that -faligned-new=8 can be used as a workaround in this case,
even in pre-c++17 modes, so the issue doesn't look that bad in the end.

[Bug target/97025] In -m32 mode the alignment of pointers returned by malloc or operator new is less than alignof(std::max_align_t)

2020-09-11 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97025

--- Comment #2 from Mikhail Kremniov  ---
(In reply to Andrew Pinski from comment #1)
> malloc is not controlled by gcc.

Yeah, I shouldn't have mentioned malloc because there seems to be no
requirement for it to align the returned addresses by alignof(max_align_t).
But new-expression should still return properly aligned objects, shouldn't it?
So it looks like this issue is C++-specific after all.

[Bug c++/97025] New: In -m32 mode the alignment of pointers returned by malloc or operator new is less than alignof(std::max_align_t)

2020-09-11 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97025

Bug ID: 97025
   Summary: In -m32 mode the alignment of pointers returned by
malloc or operator new is less than
alignof(std::max_align_t)
   Product: gcc
   Version: 10.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

Created attachment 49210
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49210&action=edit
The failing code

The attached code fails when compiled with -m32:

$ g++-10.2.0 gcc_alignment_issue_in_m32_mode.cpp -o test -std=c++17 -m32 &&
./test
test: gcc_alignment_issue_in_m32_mode.cpp:23: int main(): Assertion
`UIntPtr(p2.get()) % alignof(Type) == 0' failed.
Aborted


And if I remove the Type's default constructor, it just crashes:

$ g++-10.2.0 gcc_alignment_issue_in_m32_mode.cpp -o test -std=c++17 -m32
-DNO_CTOR && ./test
Segmentation fault


This happens with any version of GCC that I have in my system starting from
7.x, while 6.x works fine.
As I can see, alignof(std::max_align_t) equals 8 in 6.x and 16 in 7.x and later
versions, so this seems to be the root of the problem.

The system and compiler info:

$ cat /etc/issue
Linux Mint 17.3 Rosa \n \l

$ g++-10.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-10.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-10.2.0/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-10.2.0
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC) 



[Bug c++/95638] New: Legit-looking code doesn't work with -O2

2020-06-11 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95638

Bug ID: 95638
   Summary: Legit-looking code doesn't work with -O2
   Product: gcc
   Version: 10.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

Created attachment 48718
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48718&action=edit
The failing code

The attached code produces wrong result when build with -O2 and without
-fno-strict-aliasing, but I don't believe it does anything illegal. The only
fishy thing it does is creating a pointer to T before an object of that type is
constructed at that location (in Storage::Storage and Storage::push_back), but
the pointer is just passed to the placement new, which should be fine according
to [basic.life] (because "...using the pointer as if the pointer were of type
void*, is well-defined").


$ g++-10.1.0 -v
Using built-in specs.
COLLECT_GCC=g++-10.1.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-10.1.0/libexec/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-10.1.0
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC) 

$ g++-10.1.0 -O2 gcc10_aliasing_issue.cpp -o test -std=c++14 && ./test
Null!!!

$ g++-10.1.0 -O2 -fno-strict-aliasing gcc10_aliasing_issue.cpp -o test
-std=c++14 && ./test
OK


P.S. The same code works fine with GCC 9 and earlier versions.

[Bug c++/90505] New: gcc 9.1 rejects valid code

2019-05-16 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90505

Bug ID: 90505
   Summary: gcc 9.1 rejects valid code
   Product: gcc
   Version: 9.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

GCC 9.1 fails to compile the following code (previous versions compile it just
fine).

=== test.cpp ===
template 
struct S
{
template 
static void foo(V)
{
}

void bar()
{
foo(1);
}
};
===

=== Console ===
~/tmp$ g++-9.1.0 -c test.cpp
test.cpp: In member function ‘void S::bar()’:
test.cpp:11:20: error: no matching function for call to ‘S::foo(int)’
   11 | foo(1);
  |^
test.cpp:5:17: note: candidate: ‘template template
static void S::foo(V)’
5 | static void foo(V)
  | ^~~
test.cpp:5:17: note:   template argument deduction/substitution failed:
test.cpp:11:20: note:   mismatched types ‘V’ and ‘int’
   11 | foo(1);
  |   
===

=== Compiler version ===
~/tmp$ g++-9.1.0 -v
Using built-in specs.
COLLECT_GCC=g++-9.1.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-9.1.0/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-9.1.0
Thread model: posix
gcc version 9.1.0 (GCC) 
===

[Bug c++/87554] internal compiler error: in record_reference, at cgraphbuild.c:64

2018-10-08 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87554

--- Comment #3 from Mikhail Kremnyov  ---
FYI: 6.3.0 is able to compile the non-preprocessed source.

As for 7.x - 7.3.0 and earlier versions can't compile it due to another bug
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85470) and I don't have 7.4 at
hand.

[Bug c++/87554] internal compiler error: in record_reference, at cgraphbuild.c:64

2018-10-08 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87554

--- Comment #1 from Mikhail Kremnyov  ---
Created attachment 44808
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44808&action=edit
Preprocessed source

[Bug c++/87554] New: internal compiler error: in record_reference, at cgraphbuild.c:64

2018-10-08 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87554

Bug ID: 87554
   Summary: internal compiler error: in record_reference, at
cgraphbuild.c:64
   Product: gcc
   Version: 8.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

GCC crashes when compiling the attached file with -O1
==
$ g++-8.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-8.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-8.2.0/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-8.2.0
Thread model: posix
gcc version 8.2.0 (GCC)

$ g++-8.2.0 -O1 -c test.cpp.i -o test.o
cc1plus: internal compiler error: in record_reference, at cgraphbuild.c:64
0x59361b record_reference
../.././gcc/cgraphbuild.c:64
0xd8aad3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set >*))
../.././gcc/tree.c:11396
0xd8af7a walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set >*))
../.././gcc/tree.c:11712
0x7e1bf6 record_references_in_initializer(tree_node*, bool)
../.././gcc/cgraphbuild.c:386
0xdbd406 varpool_node::analyze()
../.././gcc/varpool.c:534
0x7e5fbe analyze_functions
../.././gcc/cgraphunit.c:1185
0x7e6c72 symbol_table::finalize_compilation_unit()
../.././gcc/cgraphunit.c:2691
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++/87512] New: Error: the type ‘const auto’ of ‘constexpr’ variable is not literal

2018-10-04 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87512

Bug ID: 87512
   Summary: Error: the type ‘const auto’ of ‘constexpr’ variable
is not literal
   Product: gcc
   Version: 8.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

Created attachment 44779
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44779&action=edit
Preprocessed source

The following code fails to compile:
==
#include 

template 
inline constexpr auto IsPtr = std::is_pointer::value;

class Foo;
class Bar;

template 
void foo(T1, T2);

template 
std::enable_if_t> foo(T, Foo);

template <>
void foo(Bar, Bar);
==

The error:
==
$ g++-8.2.0 -c -std=c++17 test.cpp
test.cpp: In instantiation of ‘constexpr const auto IsPtr’:
test.cpp:13:18:   required by substitution of ‘template
std::enable_if_t > foo(T, Foo) [with T = Bar]’
test.cpp:16:23:   required from here
test.cpp:4:23: error: the type ‘const auto’ of ‘constexpr’ variable
‘IsPtr’ is not literal
 inline constexpr auto IsPtr = std::is_pointer::value;
   ^
test.cpp:4:23: error: ‘const auto IsPtr’ has incomplete type
==

GCC version:
==
$ g++-8.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-8.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-8.2.0/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-8.2.0
Thread model: posix
gcc version 8.2.0 (GCC)
==

The preprocessed source is attached.

P.S.
1) Clang is able to compile it.
2) Changing "auto" to "bool" in the definition of IsPtr fixes the error.

[Bug c++/85470] New: Strange error about "call to non-constexpr function"

2018-04-19 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85470

Bug ID: 85470
   Summary: Strange error about "call to non-constexpr function"
   Product: gcc
   Version: 7.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

GCC 7 fails to compile the following code:

 test.cpp 

template 
struct StaticObject
{
static T& create()
{
  static T t;
  return t;
}

static T & instance;
};

template  T & StaticObject::instance = StaticObject::create();

extern template class StaticObject;

void test()
{
StaticObject::instance;
}

 command line -

$ g++-7.3.0 -v
Using built-in specs.
COLLECT_GCC=g++-7.3.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-7.3.0/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-7.3.0
Thread model: posix
gcc version 7.3.0 (GCC)

$ g++-7.3.0 -c test.cpp
test.cpp: In instantiation of ‘int& StaticObject::instance’:
test.cpp:19:24:   required from here
test.cpp:13:75: error: call to non-constexpr function ‘static T&
StaticObject::create() [with T = int]’
 template  T & StaticObject::instance = StaticObject::create();


P.S. I also tried 7.1 (same error) and 6.3 (no error)

[Bug c++/85118] New: Error when using std::bind with a generic lambda - "cannot bind 'const volatile char&' to an rvalue of type 'const volatile char'"

2018-03-29 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85118

Bug ID: 85118
   Summary: Error when using std::bind with a generic lambda -
"cannot bind 'const volatile char&' to an rvalue of
type 'const volatile char'"
   Product: gcc
   Version: 7.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
      Reporter: officesamurai at gmail dot com
  Target Milestone: ---

Created attachment 43794
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43794&action=edit
Preprocessed test code

Seemingly innocent code gives a strange error "cannot bind 'const volatile
char&' to an rvalue of type 'const volatile char'".

The code:
===
#include 

template 
bool isOneOf(const T& /*t*/)
{
return false;
}

template 
bool isOneOf(const T& t, const FirstType& firstValue, const Tail&... tail)
{
return t == firstValue || isOneOf(t, tail...);
}

int main()
{
const auto isOneOfHelper = [](auto&&... params)
{
return isOneOf(std::forward(params)...);
};

auto isO = std::bind(isOneOfHelper, std::placeholders::_1, 'o');

isO('o');
}
===

GCC version:
===
$ g++-7.3.0 -v
Using built-in specs.
COLLECT_GCC=g++-7.3.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-7.3.0/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-7.3.0
Thread model: posix
gcc version 7.3.0 (GCC)
===

The error:
===
$ g++-7.3.0 ~/tmp/test.cpp -std=c++14 -o test -save-temps
/home/brd/tmp/test.cpp: In instantiation of ‘main()::
[with auto:1 = {char, const volatile char}]’:
/home/brd/tmp/test.cpp:17:51:   required by substitution of ‘template main()operator decltype (((const
main()::*)((const main()::*
const)0))->operator()(static_cast(main::__lambda0::_FUN::)
...)) (*)(auto:1&& ...)() const [with auto:1 = {char, const volatile char}]’
/home/brd/soft/gcc-7.3.0/include/c++/7.3.0/type_traits:2428:26:   required by
substitution of ‘template static
std::__result_of_success()((declval<_Args>)()...)),
std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn =
const volatile main()::&; _Args = {char&&, const volatile
char&}]’
/home/brd/soft/gcc-7.3.0/include/c++/7.3.0/type_traits:2439:55:   required from
‘struct std::__result_of_impl&, char&&, const volatile char&>’
/home/brd/soft/gcc-7.3.0/include/c++/7.3.0/type_traits:2444:12:   required from
‘struct std::__invoke_result&,
char&&, const volatile char&>’
/home/brd/soft/gcc-7.3.0/include/c++/7.3.0/type_traits:2457:12:   required from
‘class std::result_of&(char&&,
const volatile char&)>’
/home/brd/soft/gcc-7.3.0/include/c++/7.3.0/functional:511:72:   required by
substitution of ‘template template using _Res_type_impl = typename
std::result_of<_Fn&(std::_Bind<_Functor(_Bound_args ...)>::_Mu_type<_BArgs,
_CallArgs>&& ...)>::type [with _Fn = std::add_cv
>::type; _CallArgs = std::tuple; _BArgs =
{std::add_cv >::type, std::add_cv::type}; _Functor =
main()::; _Bound_args = {std::_Placeholder<1>, char}]’
/home/brd/soft/gcc-7.3.0/include/c++/7.3.0/functional:524:46:   required by
substitution of ‘template template class __cv_quals>
template template class
__cv_quals> using _Res_type_cv = std::_Bind<_Functor(_Bound_args
...)>::_Res_type_impl::value + 1)),
_Functor>::type>::type, _CallArgs, typename __cv_quals<_Bound_args>::type ...>
[with _CallArgs = std::tuple; __cv_quals = std::add_cv; _Functor =
main()::; _Bound_args = {std::_Placeholder<1>, char}]’
/home/brd/soft/gcc-7.3.0/include/c++/7.3.0/functional:585:9:   required by
substitution of ‘template _Result
std::_Bind(std::_Placeholder<1>,
char)>::operator()<_Args ..., _Result>(_Args&& ...) const volatile [with _Args
= {char}; _Result = ]’
/home/brd/tmp/test.cpp:24:12:   required from here
/home/brd/tmp/test.cpp:19:23: error: no matching function for call to
‘isOneOf(char, const volatile char)’
 return isOneOf(std::forward(params)...);
~~~^~~
/home/brd/tmp/test.cpp:4:6: note: candidate: template bool
isOneOf(const T&)
 bool isOneOf(const T& /*t*/)
  ^~~
/home/brd/tmp/test.cpp:4:6: note:   template argument deduction/substitution
failed:
/home/brd/tmp/test.cpp:19:23: note:   candidate expects 1 argument, 2 provided
 return isOneOf(std::forward(params)...);
~~~^~~
/home/brd/tmp/test.cpp:10:6: note: candidate: bool isOneOf(const T&, const
FirstType&, const Tail& ...) [with T = char; FirstType = volatile char

[Bug c++/66139] destructor not called for members of partially constructed anonymous struct/array

2017-03-10 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66139

Mikhail Kremnyov  changed:

   What|Removed |Added

 CC||officesamurai at gmail dot com

--- Comment #1 from Mikhail Kremnyov  ---
This issue is also present in GCC 5.x, 6.x and the trunk.

I wonder if it's possible to increase its priority since it makes it impossible
to guarantee code exception safety.

[Bug c++/68138] New: "operator== is ambiguous" when comparing a tuple containing values with one containing refs

2015-10-28 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68138

Bug ID: 68138
   Summary: "operator== is ambiguous" when comparing a tuple
containing values with one containing refs
   Product: gcc
   Version: 5.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: officesamurai at gmail dot com
  Target Milestone: ---

Created attachment 36610
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36610&action=edit
test code (also in the text)

The test code is:

#include 

struct T
{
bool operator==(const T&) const
{
return true;
}
};

int main()
{
T t;
std::tuple t1;
std::tuple t2(t, t);

bool b = t1 == t2;
}


The result is:


g++ test.cpp  -std=c++11
test.cpp: In function ‘int main()’:
test.cpp:17:20: error: request for member ‘operator==’ is ambiguous
 bool b = t1 == t2;
^
test.cpp:5:10: note: candidates are: bool T::operator==(const T&) const
 bool operator==(const T&) const
  ^
test.cpp:5:10: note: bool T::operator==(const T&) const


Note: Clang is able to compile this code even when libstdc++ is used.

[Bug c++/58354] variadic template ambiguous

2014-11-19 Thread officesamurai at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58354

Mikhail Kremnyov  changed:

   What|Removed |Added

 CC||officesamurai at gmail dot com

--- Comment #1 from Mikhail Kremnyov  ---
There is a simpler case.

test.cpp:
template 
void foo(T2, Types...)
{
}

template 
void foo(int, Types...)
{
}

int main()
{
  foo(1, 2);
}

Command line:
g++ -std=c++11 test.cpp -o test

Output:
test.cpp: In function ‘int main()’:
test.cpp:13:17: error: call of overloaded ‘foo(int, int)’ is ambiguous
   foo(1, 2);
 ^
test.cpp:13:17: note: candidates are:
test.cpp:2:6: note: void foo(T2, Types ...) [with T1 = void; T2 = int; Types =
{int}]
 void foo(T2, Types...)
  ^
test.cpp:7:6: note: void foo(int, Types ...) [with T1 = void; Types = {int}]
 void foo(int, Types...)

I tried this with versions 4.8.1, 4.9.1, 4.9.2 - same result.
Clang has no problems with this code.