2017-06-08 01:41:59 +08:00
/ / RUN : clang - tidy % s - checks = " -*,cert-err58-cpp " - - - std = c + + 11 - target x86_64 - pc - linux - gnu \
/ / RUN : | FileCheck % s - check - prefix = CHECK - EXCEPTIONS \
// RUN: -implicit-check-not="{{warning|error}}:"
/ / RUN : clang - tidy % s - checks = " -*,cert-err58-cpp " - - - fno - exceptions - std = c + + 11 - target x86_64 - pc - linux - gnu \
/ / RUN : | FileCheck % s - allow - empty - check - prefix = CHECK - NONEXCEPTIONS \
// RUN: -implicit-check-not="{{warning|error}}:"
2015-12-01 22:05:39 +08:00
struct S {
S ( ) noexcept ( false ) ;
} ;
struct T {
T ( ) noexcept ;
} ;
struct U {
U ( ) { }
} ;
struct V {
explicit V ( const char * ) { } // Can throw
} ;
2016-11-01 06:47:04 +08:00
struct Cleanup {
2016-10-16 17:47:10 +08:00
~ Cleanup ( ) { }
} ;
struct W {
W ( Cleanup c = { } ) noexcept ( false ) ;
} ;
2016-11-01 06:47:04 +08:00
struct X {
X ( S = { } ) noexcept ;
} ;
struct Y {
S s ;
} ;
struct Z {
T t ;
} ;
int f ( ) ;
int g ( ) noexcept ( false ) ;
int h ( ) noexcept ( true ) ;
struct UserConv_Bad {
operator int ( ) noexcept ( false ) ;
} ;
struct UserConv_Good {
operator int ( ) noexcept ;
} ;
UserConv_Bad some_bad_func ( ) noexcept ;
UserConv_Good some_good_func ( ) noexcept ;
2015-12-01 22:05:39 +08:00
S s ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
// CHECK-EXCEPTIONS: 9:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2015-12-01 22:05:39 +08:00
T t ; // ok
U u ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'u' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 17:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2015-12-01 22:05:39 +08:00
V v ( " v " ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'v' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 21:12: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-10-16 17:47:10 +08:00
W w ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'w' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 29:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-11-01 06:47:04 +08:00
X x1 ( S { } ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'x1' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 9:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-11-01 06:47:04 +08:00
X x2 ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'x2' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 9:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-11-01 06:47:04 +08:00
Y y ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'y' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 36:8: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-11-01 06:47:04 +08:00
Z z ;
int i = f ( ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:5: warning: initialization of 'i' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 44:5: note: possibly throwing function declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-11-01 06:47:04 +08:00
int j = g ( ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:5: warning: initialization of 'j' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 45:5: note: possibly throwing function declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-11-01 06:47:04 +08:00
int k = h ( ) ;
int l = some_bad_func ( ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:5: warning: initialization of 'l' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 49:3: note: possibly throwing function declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-11-01 06:47:04 +08:00
int m = some_good_func ( ) ;
typedef decltype ( sizeof ( int ) ) size_t ;
inline void * operator new ( size_t sz , void * here ) noexcept { return here ; }
char n [ sizeof ( int ) ] ;
int * o = new ( n ) int ( ) ;
int * p = new int ( ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:6: warning: initialization of 'p' with static storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
2015-12-01 22:05:39 +08:00
2016-09-26 23:00:45 +08:00
thread_local S s3 ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:16: warning: initialization of 's3' with thread_local storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
thread_local T t3 ; // ok
thread_local U u3 ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:16: warning: initialization of 'u3' with thread_local storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
thread_local V v3 ( " v " ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:16: warning: initialization of 'v3' with thread_local storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-10-16 17:47:10 +08:00
thread_local W w3 ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:16: warning: initialization of 'w3' with thread_local storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
2016-10-16 17:47:10 +08:00
void f ( S s1 , T t1 , U u1 , V v1 , W w1 ) { // ok, ok, ok, ok, ok
2015-12-01 22:05:39 +08:00
S s2 ; // ok
T t2 ; // ok
U u2 ; // ok
V v2 ( " v " ) ; // ok
2016-10-16 17:47:10 +08:00
W w2 ; // ok
2015-12-01 22:05:39 +08:00
2016-09-26 23:00:45 +08:00
thread_local S s3 ; // ok
2015-12-01 22:05:39 +08:00
thread_local T t3 ; // ok
2016-09-26 23:00:45 +08:00
thread_local U u3 ; // ok
thread_local V v3 ( " v " ) ; // ok
2016-10-16 17:47:10 +08:00
thread_local W w3 ; // ok
2015-12-01 22:05:39 +08:00
2016-09-26 23:00:45 +08:00
static S s4 ; // ok
2015-12-01 22:05:39 +08:00
static T t4 ; // ok
2016-09-26 23:00:45 +08:00
static U u4 ; // ok
static V v4 ( " v " ) ; // ok
2016-10-16 17:47:10 +08:00
static W w4 ; // ok
2015-12-01 22:05:39 +08:00
}
2016-09-26 23:00:45 +08:00
namespace {
S s ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
// CHECK-EXCEPTIONS: 9:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
T t ; // ok
U u ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'u' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 17:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
V v ( " v " ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'v' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 21:12: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-10-16 17:47:10 +08:00
W w ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'w' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 29:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
thread_local S s3 ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:16: warning: initialization of 's3' with thread_local storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
thread_local T t3 ; // ok
thread_local U u3 ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:16: warning: initialization of 'u3' with thread_local storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
thread_local V v3 ( " v " ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:16: warning: initialization of 'v3' with thread_local storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-10-16 17:47:10 +08:00
thread_local W w3 ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:16: warning: initialization of 'w3' with thread_local storage duration may throw an exception that cannot be caught
// CHECK-NONEXCEPTIONS-NOT: warning:
} ; // namespace
2016-09-26 23:00:45 +08:00
class Statics {
2016-11-01 06:47:04 +08:00
static S s ; // warn when initialized
2016-09-26 23:00:45 +08:00
static T t ; // ok
2016-11-01 06:47:04 +08:00
static U u ; // warn when initialized
static V v ; // warn when initialized
static W w ; // warn when initialized
2016-09-26 23:00:45 +08:00
void f ( S s , T t , U u , V v ) {
S s2 ; // ok
T t2 ; // ok
U u2 ; // ok
V v2 ( " v " ) ; // ok
2016-10-16 17:47:10 +08:00
W w2 ; // ok
2016-09-26 23:00:45 +08:00
thread_local S s3 ; // ok
thread_local T t3 ; // ok
thread_local U u3 ; // ok
thread_local V v3 ( " v " ) ; // ok
2016-10-16 17:47:10 +08:00
thread_local W w3 ; // ok
2016-09-26 23:00:45 +08:00
static S s4 ; // ok
static T t4 ; // ok
static U u4 ; // ok
static V v4 ( " v " ) ; // ok
2016-10-16 17:47:10 +08:00
static W w4 ; // ok
2016-09-26 23:00:45 +08:00
}
} ;
S Statics : : s ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:12: warning: initialization of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
// CHECK-EXCEPTIONS: 9:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
T Statics : : t ;
U Statics : : u ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:12: warning: initialization of 'u' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 17:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-09-26 23:00:45 +08:00
V Statics : : v ( " v " ) ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:12: warning: initialization of 'v' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 21:12: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning:
2016-10-16 17:47:10 +08:00
W Statics : : w ;
2017-06-08 01:41:59 +08:00
// CHECK-EXCEPTIONS: :[[@LINE-1]]:12: warning: initialization of 'w' with static storage duration may throw an exception that cannot be caught
// CHECK-EXCEPTIONS: 29:3: note: possibly throwing constructor declared here
// CHECK-NONEXCEPTIONS-NOT: warning: