Skip to content

Commit b28cd27

Browse files
praetorian20iMichka
authored andcommitted
Fix errors in -std=c++11 mode
`free_operators.hpp` had a couple of instances of narrowing conversions within braced initializers, which is ill-formed since C++11. `type_traits.hpp` had two instances of aggregates being value-initialized using empty parentheses. Since these aggregates had implicitly deleted default constructors (due to the presence of `const` data members), value-initialization performs default-initialization, which is ill-formed. We need aggregate-initialization to be performed, so the initialization must use braces instead of parentheses for C++11 and later. Change-Id: Ie4d0365fed7fcccf18dfb2c0b341a3bb34abe645 Cherry-picked from the develop branch
1 parent 0f35ed8 commit b28cd27

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

unittests/data/free_operators.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ bool operator!( const number& x ){
3232
}
3333

3434
number operator*( const number& n, double i ){
35-
number n2 = { n.i * i };
35+
number n2 = { static_cast<int>(n.i * i) };
3636
return n2;
3737
}
3838

3939
number operator*( double i, const number& n ){
40-
number n2 = { n.i * i };
40+
number n2 = { static_cast<int>(n.i * i) };
4141
return n2;
4242
}
4343

unittests/data/type_traits.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,19 @@ namespace has_trivial_constructor{
576576
namespace details{
577577

578578
struct const_item{ const int values[10]; };
579-
580-
void test_const_item( const_item x = const_item() );
581-
582579
struct const_container{ const const_item items[10]; };
583580

581+
#if __cplusplus >= 201103L
582+
// C++11 and later must use braces to trigger aggregate initialization.
583+
// Using parentheses will cause value-initialization, and since the
584+
// two classes above have implicitly deleted default constructors,
585+
// that causes default initialization to be performed, which is ill-formed.
586+
void test_const_item( const_item x = const_item{} );
587+
void test_const_container( const_container x = const_container{} );
588+
#else
589+
void test_const_item( const_item x = const_item() );
584590
void test_const_container( const_container x = const_container() );
591+
#endif
585592

586593
}
587594

0 commit comments

Comments
 (0)