[Bug c++/92467] gcc miscompiles ternary expression with omitted first operand ?: involving C++ prvalues

2019-11-11 Thread st at quanttec dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92467

--- Comment #3 from Stephan Tolksdorf  ---
Calling release on tmp should set the internal pointer member to null so that
the destructor won't call the deleter on the (void*)1 ptr.

[Bug c++/92467] New: gcc miscompiles ternary expression with omitted first operand ?: involving C++ prvalues

2019-11-11 Thread st at quanttec dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92467

Bug ID: 92467
   Summary: gcc miscompiles ternary expression with omitted first
operand ?: involving C++ prvalues
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: st at quanttec dot com
  Target Milestone: ---

The current trunk version of GCC miscompiles the following code involving a
ternary expression with omitted first operand ("elvis operator"). Compiled with
`g++-9 --std=c++2a` the program prints "deleting: 1" followed by "result: 1".
The same code compiled with clang doesn't erroneously call the deleter
function.

(Note that such use of the ternary operator in C++ will become increasingly
common:
https://stackoverflow.com/questions/58368012/how-to-enable-the-c-c-conditional-with-omitted-operand-aka-elvis-operator
)


#include 
#include 

#define NOINLINE __attribute__ ((noinline))

struct Deleter {
NOINLINE void operator()(void* p) {
std::cout << "deleting: " << (uintptr_t)p << std::endl;
}
};

NOINLINE std::unique_ptr get1() {
return std::unique_ptr{(void*)1};
}
NOINLINE std::unique_ptr get2() {
return std::unique_ptr{(void*)2};
}

NOINLINE void* test() {
return (get1() ?: get2()).release();
}

int main() {
uintptr_t result = (uintptr_t)test();
std::cout << "result: " << result;
return 0;
}

[Bug c++/89486] New: GCC fails to compile designated initializer use involving implicit conversion

2019-02-24 Thread st at quanttec dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89486

Bug ID: 89486
   Summary: GCC fails to compile designated initializer use
involving implicit conversion
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: st at quanttec dot com
  Target Milestone: ---

The following code fails to compile with the current trunk version of GCC.
clang compiles the code fine.

struct P {
  int a = 0;
  void* b;
};

void f(P) {}

void test() {
  f({.b = nullptr});
}

: In function 'void test()':
:9:19: error: could not convert '{nullptr}' from '' to 'P'

9 |   f({.b = nullptr});

  |   ^

  |   |

  |   

Compiler returned: 1

[Bug c++/63207] New: ICE in expand_expr_real_l when instantiating a template with a lambda that captures a const variable with a dependent initializer

2014-09-08 Thread st at quanttec dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63207

Bug ID: 63207
   Summary: ICE in expand_expr_real_l when instantiating a
template with a lambda that captures a const variable
with a dependent initializer
   Product: gcc
   Version: 5.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: st at quanttec dot com

Compiling the following following code with the current trunk GCC results in an
ICE.

template typename T
struct Base {
  T value;
};

template typename T
struct Test : BaseT {
  T test() {
const int x = this-value;
return ([]{ return x; })();
  }
};

int main()  {
  Testint t;
  t.value = 0;
  return t.test();
}

g++ test.cpp --std=c++11 -Wall
test.cpp: In lambda function:
test.cpp:10:28: warning: ‘x’ is used uninitialized in this function
[-Wuninitialized]
 return ([]{ return x; })();
^
test.cpp:9:15: note: ‘x’ was declared here
 const int x = this-value;
   ^
test.cpp:10:28: internal compiler error: in expand_expr_real_1, at expr.c:9517
 return ([]{ return x; })();
^
0x8c96ba expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
../../gcc/gcc/expr.c:9517
0x8d0dea store_expr(tree_node*, rtx_def*, int, bool)
../../gcc/gcc/expr.c:5338
0x8d8e4b expand_assignment(tree_node*, tree_node*, bool)
../../gcc/gcc/expr.c:5124
0x7e3b33 expand_gimple_stmt_1
../../gcc/gcc/cfgexpand.c:3274
0x7e3b33 expand_gimple_stmt
../../gcc/gcc/cfgexpand.c:3376
0x7e99d3 expand_gimple_basic_block
../../gcc/gcc/cfgexpand.c:5215
0x7eb86f execute
../../gcc/gcc/cfgexpand.c:5821

[Bug c++/61838] ICE on Windows with ctors defined outside class definitions

2014-09-08 Thread st at quanttec dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61838

Stephan Tolksdorf st at quanttec dot com changed:

   What|Removed |Added

 CC||st at quanttec dot com

--- Comment #2 from Stephan Tolksdorf st at quanttec dot com ---
This regression from 4.8 seems to have been fixed on trunk but is still present
on the 4.9 branch. Could the fix be packported to 4.9?

Compiling the following simple snippet with -std=c++11 produces a segfault
with 4.9: 

template typename... Ts struct A {};
struct B { B(Aint); };
B::B(Aint) {}

cc1plus: internal compiler error: Segmentation fault
0x919b1f crash_signal
../../gcc/gcc/toplev.c:337
0x6a5ea2 analyze_functions
../../gcc/gcc/cgraphunit.c:1043
0x6a6f4f finalize_compilation_unit()
../../gcc/gcc/cgraphunit.c:2327
0x559ebb cp_write_global_declarations()
../../gcc/gcc/cp/decl2.c:4616


[Bug c++/59879] New: arrays in return statements or default arguments decay too early

2014-01-19 Thread st at quanttec dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59879

Bug ID: 59879
   Summary: arrays in return statements or default arguments decay
too early
   Product: gcc
   Version: 4.8.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: st at quanttec dot com

g++ seems to decay arrays in return statements or default arguments too early. 

The following sample fails to compile with 4.8.2 and the current GIT master
version of gcc but compiles cleanly in clang:

--
struct Test {
  template int N
  Test(const char (array)[N]) {}
};

Test test() {
  return test;
}

void test2(Test arg = test) {}

int main() {
  test();
  test2();
}
--

g++ test.cpp
test.cpp: In function ‘Test test()’:
test.cpp:8:10: error: could not convert ‘(const char*)test’ from ‘const
char*’ to ‘Test’
   return test;
  ^
test.cpp: In function ‘int main()’:
test.cpp:15:9: error: could not convert ‘(const char*)test’ from ‘const
char*’ to ‘Test’
   test2();
 ^

[Bug c++/56859] alignas() fails in template

2013-12-11 Thread st at quanttec dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56859

Stephan Tolksdorf st at quanttec dot com changed:

   What|Removed |Added

 CC||st at quanttec dot com

--- Comment #6 from Stephan Tolksdorf st at quanttec dot com ---
The following example still fails with the current trunk GCC. Should this bug
be reopened, or should I file a new one?

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

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


[Bug c++/51253] [C++11][DR 1030] Evaluation order (sequenced-before relation) among initializer-clauses in braced-init-list

2013-10-23 Thread st at quanttec dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253

Stephan Tolksdorf st at quanttec dot com changed:

   What|Removed |Added

 CC||st at quanttec dot com

--- Comment #4 from Stephan Tolksdorf st at quanttec dot com ---
I just stumbled over this bug with the current trunk version of GCC. It's a
pretty ugly bug.


[Bug c++/58855] New: Attributes ignored on type alias in template

2013-10-23 Thread st at quanttec dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58855

Bug ID: 58855
   Summary: Attributes ignored on type alias in template
   Product: gcc
   Version: 4.9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: st at quanttec dot com

When compiling the following example the current trunk version of GCC accepts
the attribute in the typedef but not the semantically equivalent type alias. 

template typename T
void test(T*) {
  using T0 = int __attribute__((aligned(1)));
  static_assert(alignof(T0) == 1, wrong alignment); // no error

  typedef T __attribute__((aligned(1))) T1;
  static_assert(alignof(T1) == 1, wrong alignment); // no error

  using T2 = T __attribute__((aligned(1)));
  static_assert(alignof(T2) == 1, wrong alignment); // error
}

int main() {
  test((int*)0);
  return 0;
}

 g++ -std=c++11 -Wall -Wextra test.cpp
test.cpp: In function ‘void test(T*)’:
test.cpp:9:42: warning: ignoring attributes applied to dependent type ‘T’
without an associated declaration [-Wattributes]
   using T2 = T __attribute__((aligned(1)));
  ^
test.cpp: In instantiation of ‘void test(T*) [with T = int]’:
test.cpp:14:15:   required from here
test.cpp:10:3: error: static assertion failed: wrong alignment
   static_assert(alignof(T2) == 1, wrong alignment); // error
   ^

[Bug c++/58856] New: [4.9 Regression] spurious 'wrong number of template arguments' error for template alias

2013-10-23 Thread st at quanttec dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58856

Bug ID: 58856
   Summary: [4.9 Regression] spurious 'wrong number of template
arguments' error for template alias
   Product: gcc
   Version: 4.9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: st at quanttec dot com

The current trunk version of GCC fails to compile the following valid sample

template typename T
struct U1 {};

template typename T1, typename... Ts
using U2 = U1T1;

template typename T1, typename... Ts
using U3 = U2T1, Ts...;

 g++ -std=c++11 -Wall -Wextra test.cpp
test.cpp:8:24: error: wrong number of template arguments (2, should be 1)
 using U3 = U2T1, Ts...;
^
test.cpp:2:8: error: provided for ‘templateclass T struct U1’
 struct U1 {};
^

This bug doesn't seem to exist in
g++ (GCC) 4.8.1 20130603 (Red Hat 4.8.1-1)
and in
g++ (Built by MinGW-builds project) 4.9.0 20130717 (experimental)

[Bug c++/57712] New: GCC fails to to match out-of-line template member function definition with declaration

2013-06-25 Thread st at quanttec dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57712

Bug ID: 57712
   Summary: GCC fails to to match out-of-line template member
function definition with declaration
   Product: gcc
   Version: 4.8.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: st at quanttec dot com

g++ 4.8.1 fails to compile the following C++11 code:

struct Test {
  int method(int value) { return value; }

  template typename T
  auto test(T value) - decltype(this-method(value));
};

template typename T
auto Test::test(T value) - decltype(this-method(value)) {
  return this-method(value);
}

int main() {
  Test t;
  return t.test(0);
}

 g++ --std=c++11 test.cpp
test.cpp:9:6: error: prototype for ‘decltype (this-.Test::method(value))
Test::test(T)’ does not match any in class ‘Test’
 auto Test::test(T value) - decltype(this-method(value)) {
  ^
test.cpp:5:8: error: candidate is: templateclass T decltype
(this-.Test::method(value)) Test::test(T)
   auto test(T value) - decltype(this-method(value));


If the member function is defined inline, gcc compiles it fine.

[Bug c++/56643] New: Failure to match noexcept specifier of friend template function in template class

2013-03-17 Thread st at quanttec dot com

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56643

 Bug #: 56643
   Summary: Failure to match noexcept specifier of friend template
function in template class
Classification: Unclassified
   Product: gcc
   Version: 4.7.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: s...@quanttec.com


The current SVN version of g++ fails to match the noexcept specifier of the
friend declaration and definition of the test template function in the
following code:

template int N
struct Test {
template int M
friend void test(TestM arg) noexcept(M == 0);
};

template int N
void test(TestN arg) noexcept(N == 0) {}

int main() {
Test0 t;
test(t);
return 0;
}

I get the following error:

g++ --std=c++11 test.cpp
test.cpp: In instantiation of ‘struct Test0’:
test.cpp:12:13:   required from here
test.cpp:5:17: error: declaration of ‘templateint M void test(TestN)
noexcept (uninstantiated)’ has a different exception specifier
 friend void test(TestM arg) noexcept(M == 0);
 ^
test.cpp:9:6: error: from previous declaration ‘templateint N void
test(TestN) noexcept ((N == 0))’
 void test(TestN arg) noexcept(N == 0) {}
  ^

The error message seems to suggest that g++ confuses the template parameter of
the friend function declaration and the template parameter of the containing
class (note the 'N' in the line starting with 'test.cpp:5:17: error').

g++ 4.7.2 reports a similar error.


[Bug c++/56633] New: Overload selection error for non-static data member initialization with initializer list in template class

2013-03-16 Thread st at quanttec dot com

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56633

 Bug #: 56633
   Summary: Overload selection error for non-static data member
initialization with initializer list in template class
Classification: Unclassified
   Product: gcc
   Version: 4.8.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: s...@quanttec.com


g++ (the current SVN version) fails to compile the following valid c++11 code

#include atomic

struct Test1 {
std::atomicint value2{0}; // no problem here
};

template typename T // T is not used
struct Test2 {
std::atomicint value2{0}; // fails to compile
};

int main() {
Test1 test;
Test2int test2;
return 0;
}

The following error message is generated for Test2:

g++ --std=c++11 test.cpp
test.cpp: In constructor ‘constexpr Test2int::Test2()’:
test.cpp:8:8: error: use of deleted function ‘std::atomicint::atomic(const
std::atomicint)’
 struct Test2 {
^
In file included from test.cpp:1:0:
/opt/gcc/include/c++/4.8.0/atomic:601:7: error: declared here
   atomic(const atomic) = delete;
   ^
test.cpp: In function ‘int main()’:
test.cpp:14:16: note: synthesized method ‘constexpr Test2int::Test2()’ first
required here 
 Test2int test2;


[Bug c++/56420] New: Arithmetic error in computation with compile time unsigned __int128 constant

2013-02-21 Thread st at quanttec dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56420



 Bug #: 56420

   Summary: Arithmetic error in computation with compile time

unsigned __int128 constant

Classification: Unclassified

   Product: gcc

   Version: unknown

Status: UNCONFIRMED

  Severity: normal

  Priority: P3

 Component: c++

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: s...@quanttec.com





With GCC 4.8 (x86-64, snapshot 20130203 on Linux) the following simple test

case demonstrates an arithmetic bug for code involving a static unsigned

__int128 constant. This seems to be a regression from GCC 4.7.





#include iostream



typedef unsigned __int128 uint128_t;



static const uint128_t c = ((uint128_t)-1ULL  64) + (1ULL  63);



int main() {

// use volatile to prevent optimizer from optimizing the test

volatile uint128_t a = (uint128_t)1  127;

volatile uint128_t b = 1;



volatile uint128_t cc = c;



uint128_t result1 = a - b*c;

uint128_t result2 = a - b*cc;



if (result1 != result2) {

std::cout  Error: results differ.\n;

return 1;

} else {

std::cout  No error.\n;

return 0;

}

}


[Bug middle-end/56420] [4.8 Regression] Arithmetic error in computation with compile time unsigned __int128 constant

2013-02-21 Thread st at quanttec dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56420



--- Comment #5 from Stephan Tolksdorf st at quanttec dot com 2013-02-21 
21:38:27 UTC ---

That was fast, thanks!