diff --git a/src/pending_changes/edg-28892-pointer-integer-cast.txt b/src/pending_changes/edg-28892-pointer-integer-cast.txt new file mode 100644 index 0000000000..b45c28c076 --- /dev/null +++ b/src/pending_changes/edg-28892-pointer-integer-cast.txt @@ -0,0 +1,13 @@ +[GH #454] +GNU C++ mode: casts of pointers to integer types that are too small + +In GNU C++ mode (including Clang mode), a cast of a pointer to an integer type +too small to hold all of its bits was accepted with a warning. GCC 4.0 and +later, and Clang, reject such casts, and the standard requires a diagnostic. +They are now errors, except when emulating GCC versions before 4.0, which +accepted them with a warning. For example, with --g++ on a target with 64-bit +pointers: + + unsigned char narrow(void *p) { + return reinterpret_cast(p); // Now an error. + } diff --git a/src/types.c b/src/types.c index 3e8a3aed1b..26421ebb7d 100644 --- a/src/types.c +++ b/src/types.c @@ -14037,14 +14037,16 @@ well as C++ mode. ) || (is_nullptr(source_type) && !source_type->incomplete)) && is_integral(dest_type) && - (C_mode() || ms_extensions || gpp_mode || + (C_mode() || ms_extensions || gpp_version_is(<40000) || dest_of_ptr_cast_big_enough(source_type, dest_type))) { /* Pointer or std::nullptr_t (but not the managed nullptr type, identified by being incomplete) --> integral is okay -- In C mode, always (size of destination is not an issue; see 6.3.4 in the ISO C89 standard) -- In C++ mode, if (a) the integer is big enough or (b) it's - not big enough but we're compiling in Microsoft or GNU mode. */ + not big enough but we're compiling in Microsoft mode or + emulating a GNU C++ version before 4.0 (which accepted such + casts with a warning). */ okay = TRUE; if (!dest_of_ptr_cast_big_enough(source_type, dest_type)) { /* The destination is not large enough to hold all of the bits diff --git a/tests/expectations/edg_x86_32/imported.log b/tests/expectations/edg_x86_32/imported.log index a3fcb653c1..f886d9aae8 100644 --- a/tests/expectations/edg_x86_32/imported.log +++ b/tests/expectations/edg_x86_32/imported.log @@ -918,6 +918,7 @@ gnu/cpp/other/pr49133.sft.cpp:rp:-DTEST_NUMBER=1:FAIL(COMPILE): gnu/cpp/other/profile1.sft.cpp:rp:-DTEST_NUMBER=1:CATASTROPHE(COMPILE): gnu/cpp/other/ucnid-1-utf8.sft.cpp:rp:-DTEST_NUMBER=1:FAIL(COMPILE): gnu/cpp/other/ucnid-1.sft.cpp:rp:-DTEST_NUMBER=1:FAIL(COMPILE): +gnu/cpp/parse/cast1.sft.cpp:fp:-DTEST_NUMBER=1 -w:PASS: gnu/cpp/parse/lookup1.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: gnu/cpp/parse/offsetof2.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: gnu/cpp/parse/offsetof3.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: diff --git a/tests/expectations/edg_x86_32_cp/imported.log b/tests/expectations/edg_x86_32_cp/imported.log index 80dd7714e7..eae669fbf8 100644 --- a/tests/expectations/edg_x86_32_cp/imported.log +++ b/tests/expectations/edg_x86_32_cp/imported.log @@ -1129,6 +1129,7 @@ gnu/cpp/other/ucnid-1-utf8.sft.cpp:rp:-DTEST_NUMBER=1:FAIL(COMPILE): gnu/cpp/other/ucnid-1.sft.cpp:rp:-DTEST_NUMBER=1:FAIL(COMPILE): gnu/cpp/overload/defarg5.sft.cpp:fn:-DTEST_NUMBER=1:ABORT: gnu/cpp/overload/volatile2.sft.cpp:fp:-DTEST_NUMBER=1 --c++11:FAIL: +gnu/cpp/parse/cast1.sft.cpp:fp:-DTEST_NUMBER=1 -w:PASS: gnu/cpp/parse/crash30.sft.cpp:fn:-DTEST_NUMBER=1:PASS: gnu/cpp/parse/crash75.sft.cpp:fn:-DTEST_NUMBER=1:PASS: gnu/cpp/parse/defarg5.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: diff --git a/tests/expectations/edg_x86_64/imported.log b/tests/expectations/edg_x86_64/imported.log index fbbfdb7f73..ae39603429 100644 --- a/tests/expectations/edg_x86_64/imported.log +++ b/tests/expectations/edg_x86_64/imported.log @@ -8658,6 +8658,7 @@ gnu/cpp/parse/ambig14.sft.cpp:fp:-DTEST_NUMBER=1 --c++11:FAIL: gnu/cpp/parse/array-size2.sft.cpp:fn:-DTEST_NUMBER=1:FAIL: gnu/cpp/parse/attr3.sft.cpp:fn:-DTEST_NUMBER=1 --c++23 --c++20:FAIL: gnu/cpp/parse/bitfield5.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: +gnu/cpp/parse/cast1.sft.cpp:fp:-DTEST_NUMBER=1 -w:FAIL: gnu/cpp/parse/concat1.sft.cpp:fn:-DTEST_NUMBER=1:FAIL: gnu/cpp/parse/constructor2.sft.cpp:fn:-DTEST_NUMBER=1 --c++20:FAIL: gnu/cpp/parse/constructor3.sft.cpp:fn:-DTEST_NUMBER=1:FAIL: @@ -8885,7 +8886,6 @@ gnu/cpp/template/redecl2.sft.cpp:fn:-DTEST_NUMBER=1:FAIL: gnu/cpp/template/repo3.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: gnu/cpp/template/sfinae-dr657.sft.cpp:fn:-DTEST_NUMBER=1:FAIL: gnu/cpp/template/sfinae11.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: -gnu/cpp/template/sfinae13.sft.cpp:fp:-DTEST_NUMBER=1:FAIL: gnu/cpp/template/sfinae3.sft.cpp:fn:-DTEST_NUMBER=1:FAIL: gnu/cpp/template/shadow2.sft.cpp:fn:-DTEST_NUMBER=1:FAIL: gnu/cpp/template/sizeof11.sft.cpp:fn:-DTEST_NUMBER=1:FAIL: diff --git a/tests/tests/imported/clang/cpp/CXX/temp/temp.res/.p4.rto/default.1.1.txt b/tests/tests/imported/clang/cpp/CXX/temp/temp.res/.p4.rto/default.1.1.txt index 97c4e36ee6..e96f9db390 100644 --- a/tests/tests/imported/clang/cpp/CXX/temp/temp.res/.p4.rto/default.1.1.txt +++ b/tests/tests/imported/clang/cpp/CXX/temp/temp.res/.p4.rto/default.1.1.txt @@ -59,7 +59,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers enum E : T::type {}; // expected-error{{missing 'typename'}} ^ -"Test_name.c", line 184: warning: conversion from pointer to smaller integer +"Test_name.c", line 184: error: invalid type conversion friend X::X(T::type = (int)(void(*)(typename T::type))(nullptr)); // expected-error {{friend declaration specifying a default argument must be a definition}} ^ @@ -67,7 +67,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers friend X::X(T::type = (int)(void(*)(T::type))(nullptr)); // expected-error {{friend declaration specifying a default argument must be a definition}} \ ^ -"Test_name.c", line 185: warning: conversion from pointer to smaller integer +"Test_name.c", line 185: error: invalid type conversion friend X::X(T::type = (int)(void(*)(T::type))(nullptr)); // expected-error {{friend declaration specifying a default argument must be a definition}} \ ^ @@ -105,4 +105,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers const auto *ConstCast = const_cast(Ptr); ^ -20 errors detected in the compilation of "Test_name.c". +22 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/CXX/temp/temp.res/.p4.rto/edg_x86_64_cp.1.1.txt b/tests/tests/imported/clang/cpp/CXX/temp/temp.res/.p4.rto/edg_x86_64_cp.1.1.txt index 57feebd46d..a94a2786b9 100644 --- a/tests/tests/imported/clang/cpp/CXX/temp/temp.res/.p4.rto/edg_x86_64_cp.1.1.txt +++ b/tests/tests/imported/clang/cpp/CXX/temp/temp.res/.p4.rto/edg_x86_64_cp.1.1.txt @@ -71,7 +71,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers enum E : T::type {}; // expected-error{{missing 'typename'}} ^ -"Test_name.c", line 184: warning: conversion from pointer to smaller integer +"Test_name.c", line 184: error: invalid type conversion friend X::X(T::type = (int)(void(*)(typename T::type))(nullptr)); // expected-error {{friend declaration specifying a default argument must be a definition}} ^ @@ -79,7 +79,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers friend X::X(T::type = (int)(void(*)(T::type))(nullptr)); // expected-error {{friend declaration specifying a default argument must be a definition}} \ ^ -"Test_name.c", line 185: warning: conversion from pointer to smaller integer +"Test_name.c", line 185: error: invalid type conversion friend X::X(T::type = (int)(void(*)(T::type))(nullptr)); // expected-error {{friend declaration specifying a default argument must be a definition}} \ ^ @@ -105,4 +105,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers ^ detected during instantiation of class "GH113324::S2 [with T=void]" at line 207 -20 errors detected in the compilation of "Test_name.c". +22 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.cstyle-cast.rto/default.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.cstyle-cast.rto/default.1.1.txt index 5def0176b9..7673e8e554 100644 --- a/tests/tests/imported/clang/cpp/SemaCXX/.cstyle-cast.rto/default.1.1.txt +++ b/tests/tests/imported/clang/cpp/SemaCXX/.cstyle-cast.rto/default.1.1.txt @@ -51,15 +51,15 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers (void)(int A::*)((int F::*)0); // expected-error {{conversion from pointer to member of class 'F' to pointer to member of class 'A' via virtual base 'B' is not allowed}} ^ -"Test_name.c", line 181: warning: conversion from pointer to smaller integer +"Test_name.c", line 181: error: invalid type conversion (void)(char)(fnp); // expected-error {{cast from pointer to smaller type 'char' loses information}} ^ -"Test_name.c", line 186: warning: conversion from pointer to smaller integer +"Test_name.c", line 186: error: invalid type conversion (void)(char)((void*)0); // expected-error {{cast from pointer to smaller type 'char' loses information}} ^ -"Test_name.c", line 187: warning: conversion from pointer to smaller integer +"Test_name.c", line 187: error: invalid type conversion (void)(char)((int*)0); // expected-error {{cast from pointer to smaller type 'char' loses information}} ^ @@ -75,4 +75,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers (void)(int structure::*)(psf); // expected-error-re {{C-style cast from 'void (structure::*)(){{( __attribute__\(\(thiscall\)\))?}}' to 'int structure::*' is not allowed}} ^ -12 errors detected in the compilation of "Test_name.c". +15 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.functional-cast.rto/default.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.functional-cast.rto/default.1.1.txt index d2256e9ed8..3744cd0f32 100644 --- a/tests/tests/imported/clang/cpp/SemaCXX/.functional-cast.rto/default.1.1.txt +++ b/tests/tests/imported/clang/cpp/SemaCXX/.functional-cast.rto/default.1.1.txt @@ -90,7 +90,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers (void)Amp((int F::*)0); // expected-error {{conversion from pointer to member of class 'F' to pointer to member of class 'A' via virtual base 'B' is not allowed}} ^ -"Test_name.c", line 245: warning: conversion from pointer to smaller integer +"Test_name.c", line 245: error: invalid type conversion (void)char(fnp); // expected-error {{cast from pointer to smaller type 'char' loses information}} ^ @@ -114,4 +114,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers (void)int_ref(); // expected-error {{reference to type 'int' requires an initializer}} ^ -19 errors detected in the compilation of "Test_name.c". +20 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.nullptr.rto/default.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.nullptr.rto/default.1.1.txt index 26b71f52d9..bad843f799 100644 --- a/tests/tests/imported/clang/cpp/SemaCXX/.nullptr.rto/default.1.1.txt +++ b/tests/tests/imported/clang/cpp/SemaCXX/.nullptr.rto/default.1.1.txt @@ -38,7 +38,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers (void)&nullptr; ^ -"SemaCXX/nullptr.cpp", line 68: warning: conversion from pointer to smaller integer +"SemaCXX/nullptr.cpp", line 68: error: invalid type conversion (void)reinterpret_cast(nullptr); ^ @@ -78,4 +78,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers void *q = null(); ^ -11 errors detected in the compilation of "Test_name.c". +12 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/default.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/default.1.1.txt index b4d2311bef..d7b2571285 100644 --- a/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/default.1.1.txt +++ b/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/default.1.1.txt @@ -19,7 +19,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers const int ci = 0; ^ -"SemaCXX/reinterpret-cast.cpp", line 45: warning: conversion from pointer to smaller integer +"SemaCXX/reinterpret-cast.cpp", line 45: error: invalid type conversion (void)reinterpret_cast(fnp); ^ @@ -123,4 +123,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers (void)*reinterpret_cast(data); ^ -15 errors detected in the compilation of "Test_name.c". +16 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/edg_x86_32_cp.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/edg_x86_32_cp.1.1.txt index 7da19c36fe..6a29d82a4e 100644 --- a/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/edg_x86_32_cp.1.1.txt +++ b/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/edg_x86_32_cp.1.1.txt @@ -19,7 +19,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers const int ci = 0; ^ -"SemaCXX/reinterpret-cast.cpp", line 45: warning: conversion from pointer to smaller integer +"SemaCXX/reinterpret-cast.cpp", line 45: error: invalid type conversion (void)reinterpret_cast(fnp); ^ @@ -147,4 +147,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers const int data[size]; ^ -15 errors detected in the compilation of "Test_name.c". +16 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/edg_x86_64_cp.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/edg_x86_64_cp.1.1.txt index 7da19c36fe..6a29d82a4e 100644 --- a/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/edg_x86_64_cp.1.1.txt +++ b/tests/tests/imported/clang/cpp/SemaCXX/.reinterpret-cast.rto/edg_x86_64_cp.1.1.txt @@ -19,7 +19,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers const int ci = 0; ^ -"SemaCXX/reinterpret-cast.cpp", line 45: warning: conversion from pointer to smaller integer +"SemaCXX/reinterpret-cast.cpp", line 45: error: invalid type conversion (void)reinterpret_cast(fnp); ^ @@ -147,4 +147,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers const int data[size]; ^ -15 errors detected in the compilation of "Test_name.c". +16 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/clang/cpp/SemaCXX/.unknown-anytype.rto/default.1.1.txt b/tests/tests/imported/clang/cpp/SemaCXX/.unknown-anytype.rto/default.1.1.txt index e6f084cd26..5a58cdbab2 100644 --- a/tests/tests/imported/clang/cpp/SemaCXX/.unknown-anytype.rto/default.1.1.txt +++ b/tests/tests/imported/clang/cpp/SemaCXX/.unknown-anytype.rto/default.1.1.txt @@ -35,7 +35,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers extern __unknown_anytype test1(...); ^ -"Test_name.c", line 46: warning: conversion from pointer to smaller integer +"Test_name.c", line 46: error: invalid type conversion int x = (int) test1; // expected-error {{function 'test1' with unknown type must be given a function type}} ^ @@ -55,4 +55,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers extern __unknown_anytype var; ^ -13 errors detected in the compilation of "Test_name.c". +14 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/gnu/cpp/cpp0x/.nullptr04.rto/default.1.1.txt b/tests/tests/imported/gnu/cpp/cpp0x/.nullptr04.rto/default.1.1.txt index 9ce4580fe9..f4e98d7e4f 100644 --- a/tests/tests/imported/gnu/cpp/cpp0x/.nullptr04.rto/default.1.1.txt +++ b/tests/tests/imported/gnu/cpp/cpp0x/.nullptr04.rto/default.1.1.txt @@ -7,7 +7,7 @@ fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_d const int n4 = static_cast(nullptr); // { dg-error "16:invalid 'static_cast' " } ^ -"Test_name.c", line 10: warning: conversion from pointer to smaller integer +"Test_name.c", line 10: error: invalid type conversion const short int n5 = reinterpret_cast(nullptr); // { dg-error "22:cast from .std::nullptr_t. to .short int. loses precision" "" { target { ! ptr_eq_short } } } ^ @@ -19,7 +19,7 @@ fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_d const int n8 = static_cast(mynull); // { dg-error "16:invalid 'static_cast' " } ^ -"Test_name.c", line 16: warning: conversion from pointer to smaller integer +"Test_name.c", line 16: error: invalid type conversion const short int n9 = reinterpret_cast(mynull); // { dg-error "22:cast from .std::nullptr_t. to .short int. loses precision" "" { target { ! ptr_eq_short } } } ^ @@ -55,4 +55,4 @@ fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_d const intptr_t n11 = (intptr_t)mynull; ^ -2 errors detected in the compilation of "Test_name.c". +4 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/gnu/cpp/parse/.cast1.rto/default.1.1.txt b/tests/tests/imported/gnu/cpp/parse/.cast1.rto/default.1.1.txt index 5434eb7a7e..4e82e72d1e 100644 --- a/tests/tests/imported/gnu/cpp/parse/.cast1.rto/default.1.1.txt +++ b/tests/tests/imported/gnu/cpp/parse/.cast1.rto/default.1.1.txt @@ -1 +1,14 @@ fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_diagnostics -w Test_name.c +"./parse/cast1.C", line 8: error: invalid type conversion + (int((char*)0)); + ^ + +"./parse/cast1.C", line 9: error: invalid type conversion + sizeof ((int((char*)0))); + ^ + +"./parse/cast1.C", line 10: error: invalid type conversion + typeid ((int((char*)0))); + ^ + +3 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/gnu/cpp/parse/.cast1.rto/edg_x86_32.1.1.txt b/tests/tests/imported/gnu/cpp/parse/.cast1.rto/edg_x86_32.1.1.txt new file mode 100644 index 0000000000..5434eb7a7e --- /dev/null +++ b/tests/tests/imported/gnu/cpp/parse/.cast1.rto/edg_x86_32.1.1.txt @@ -0,0 +1 @@ +fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_diagnostics -w Test_name.c diff --git a/tests/tests/imported/gnu/cpp/parse/.cast1.rto/edg_x86_32_cp.1.1.txt b/tests/tests/imported/gnu/cpp/parse/.cast1.rto/edg_x86_32_cp.1.1.txt new file mode 100644 index 0000000000..5434eb7a7e --- /dev/null +++ b/tests/tests/imported/gnu/cpp/parse/.cast1.rto/edg_x86_32_cp.1.1.txt @@ -0,0 +1 @@ +fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_diagnostics -w Test_name.c diff --git a/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/default.1.1.txt b/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/default.1.1.txt index ceaa4f9bff..1c625c94ce 100644 --- a/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/default.1.1.txt +++ b/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/default.1.1.txt @@ -1,24 +1 @@ fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_diagnostics Test_name.c -"Test_name.c", line 59: warning: conversion from pointer to smaller integer - CHECK_CAST(reinterpret); - ^ - detected during: - instantiation of "check_reinterpret_cast" based on template arguments at line 59 - instantiation of class "has_reinterpret_cast [with T=void *, U=char]" at line 83 - -"Test_name.c", line 83: error: static assertion failed with "!(has_reinterpret_cast::value)" - STATIC_ASSERT(!(has_reinterpret_cast::value)); - ^ - -"Test_name.c", line 38: warning: conversion from pointer to smaller integer - typename enable_if<(sizeof(((U)create_a()), 0) > 0), yes_type>::type - ^ - detected during: - instantiation of "check_c_cast" based on template arguments at line 47 - instantiation of class "has_c_cast [with T=void *, U=char]" at line 88 - -"Test_name.c", line 88: error: static assertion failed with "!(has_c_cast::value)" - STATIC_ASSERT(!(has_c_cast::value)); - ^ - -2 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/edg_x86_32.1.1.txt b/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/edg_x86_32.1.1.txt deleted file mode 100644 index b88c5da5dc..0000000000 --- a/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/edg_x86_32.1.1.txt +++ /dev/null @@ -1,24 +0,0 @@ -fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_diagnostics Test_name.c -"Test_name.c", line 59: warning: conversion from pointer to smaller integer - CHECK_CAST(reinterpret); - ^ - detected during: - instantiation of "check_reinterpret_cast" based on template arguments at line 59 - instantiation of class "has_reinterpret_cast [with T=void *, U=char]" at line 83 - -"Test_name.c", line 83: error: the size of an array must be greater than zero - STATIC_ASSERT(!(has_reinterpret_cast::value)); - ^ - -"Test_name.c", line 38: warning: conversion from pointer to smaller integer - typename enable_if<(sizeof(((U)create_a()), 0) > 0), yes_type>::type - ^ - detected during: - instantiation of "check_c_cast" based on template arguments at line 47 - instantiation of class "has_c_cast [with T=void *, U=char]" at line 88 - -"Test_name.c", line 88: error: the size of an array must be greater than zero - STATIC_ASSERT(!(has_c_cast::value)); - ^ - -2 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/edg_x86_32_cp.1.1.txt b/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/edg_x86_32_cp.1.1.txt deleted file mode 100644 index b88c5da5dc..0000000000 --- a/tests/tests/imported/gnu/cpp/template/.sfinae13.rto/edg_x86_32_cp.1.1.txt +++ /dev/null @@ -1,24 +0,0 @@ -fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_diagnostics Test_name.c -"Test_name.c", line 59: warning: conversion from pointer to smaller integer - CHECK_CAST(reinterpret); - ^ - detected during: - instantiation of "check_reinterpret_cast" based on template arguments at line 59 - instantiation of class "has_reinterpret_cast [with T=void *, U=char]" at line 83 - -"Test_name.c", line 83: error: the size of an array must be greater than zero - STATIC_ASSERT(!(has_reinterpret_cast::value)); - ^ - -"Test_name.c", line 38: warning: conversion from pointer to smaller integer - typename enable_if<(sizeof(((U)create_a()), 0) > 0), yes_type>::type - ^ - detected during: - instantiation of "check_c_cast" based on template arguments at line 47 - instantiation of class "has_c_cast [with T=void *, U=char]" at line 88 - -"Test_name.c", line 88: error: the size of an array must be greater than zero - STATIC_ASSERT(!(has_c_cast::value)); - ^ - -2 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/regressions/.edg-28892-legacy.rto/default.1.1.txt b/tests/tests/regressions/.edg-28892-legacy.rto/default.1.1.txt new file mode 100644 index 0000000000..82372bb5eb --- /dev/null +++ b/tests/tests/regressions/.edg-28892-legacy.rto/default.1.1.txt @@ -0,0 +1,9 @@ +fe_only -DTEST_NUMBER=1 --g++ --gnu_version=30406 Test_name.c +"Test_name.c", line 11: warning: conversion from pointer to smaller integer + x = (int)ptr; + ^ + +"Test_name.c", line 12: warning: conversion from pointer to smaller integer + x = (short)ptr; + ^ + diff --git a/tests/tests/regressions/.edg-28892-legacy.rto/edg_x86_32.1.1.txt b/tests/tests/regressions/.edg-28892-legacy.rto/edg_x86_32.1.1.txt new file mode 100644 index 0000000000..23eacea638 --- /dev/null +++ b/tests/tests/regressions/.edg-28892-legacy.rto/edg_x86_32.1.1.txt @@ -0,0 +1,5 @@ +fe_only -DTEST_NUMBER=1 --g++ --gnu_version=30406 Test_name.c +"Test_name.c", line 12: warning: conversion from pointer to smaller integer + x = (short)ptr; + ^ + diff --git a/tests/tests/regressions/.edg-28892-legacy.rto/edg_x86_32_cp.1.1.txt b/tests/tests/regressions/.edg-28892-legacy.rto/edg_x86_32_cp.1.1.txt new file mode 100644 index 0000000000..23eacea638 --- /dev/null +++ b/tests/tests/regressions/.edg-28892-legacy.rto/edg_x86_32_cp.1.1.txt @@ -0,0 +1,5 @@ +fe_only -DTEST_NUMBER=1 --g++ --gnu_version=30406 Test_name.c +"Test_name.c", line 12: warning: conversion from pointer to smaller integer + x = (short)ptr; + ^ + diff --git a/tests/tests/regressions/.edg-28892-positive.rto/default.1.1.txt b/tests/tests/regressions/.edg-28892-positive.rto/default.1.1.txt new file mode 100644 index 0000000000..5141f097e3 --- /dev/null +++ b/tests/tests/regressions/.edg-28892-positive.rto/default.1.1.txt @@ -0,0 +1 @@ +fe_only -DTEST_NUMBER=1 --c++20 --g++ --gnu_version=130300 Test_name.c diff --git a/tests/tests/regressions/.edg-28892-positive.rto/default.2.1.txt b/tests/tests/regressions/.edg-28892-positive.rto/default.2.1.txt new file mode 100644 index 0000000000..19c962dc5b --- /dev/null +++ b/tests/tests/regressions/.edg-28892-positive.rto/default.2.1.txt @@ -0,0 +1 @@ +fe_only -DTEST_NUMBER=2 --c++20 --strict Test_name.c diff --git a/tests/tests/regressions/.edg-28892.rto/default.1.1.txt b/tests/tests/regressions/.edg-28892.rto/default.1.1.txt new file mode 100644 index 0000000000..e9117eb0b8 --- /dev/null +++ b/tests/tests/regressions/.edg-28892.rto/default.1.1.txt @@ -0,0 +1,10 @@ +fe_only -DTEST_NUMBER=1 --c++20 --g++ --gnu_version=130300 Test_name.c +"Test_name.c", line 7: error: invalid type conversion + return reinterpret_cast(p); // Must be an error in GNU mode. + ^ + +"Test_name.c", line 10: error: invalid type conversion + return reinterpret_cast(p); // Must also be an error. + ^ + +2 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/regressions/.edg-28892.rto/default.2.1.txt b/tests/tests/regressions/.edg-28892.rto/default.2.1.txt new file mode 100644 index 0000000000..7cd86632a0 --- /dev/null +++ b/tests/tests/regressions/.edg-28892.rto/default.2.1.txt @@ -0,0 +1,10 @@ +fe_only -DTEST_NUMBER=2 --c++20 --g++ --gnu_version=150200 Test_name.c +"Test_name.c", line 7: error: invalid type conversion + return reinterpret_cast(p); // Must be an error in GNU mode. + ^ + +"Test_name.c", line 10: error: invalid type conversion + return reinterpret_cast(p); // Must also be an error. + ^ + +2 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/regressions/.edg-28892.rto/default.3.1.txt b/tests/tests/regressions/.edg-28892.rto/default.3.1.txt new file mode 100644 index 0000000000..ff74ebcdaf --- /dev/null +++ b/tests/tests/regressions/.edg-28892.rto/default.3.1.txt @@ -0,0 +1,10 @@ +fe_only -DTEST_NUMBER=3 --c++20 --strict Test_name.c +"Test_name.c", line 7: error: invalid type conversion + return reinterpret_cast(p); // Must be an error in GNU mode. + ^ + +"Test_name.c", line 10: error: invalid type conversion + return reinterpret_cast(p); // Must also be an error. + ^ + +2 errors detected in the compilation of "Test_name.c". diff --git a/tests/tests/regressions/edg-28892-legacy.sft.cpp b/tests/tests/regressions/edg-28892-legacy.sft.cpp new file mode 100644 index 0000000000..a2e741cb69 --- /dev/null +++ b/tests/tests/regressions/edg-28892-legacy.sft.cpp @@ -0,0 +1,15 @@ +//type:fp +//options_all:--g++ --gnu_version=30406 +// GNU C++ before 4.0 accepted a cast of a pointer to an integer type that is +// too small to hold it, with a warning. That leniency is kept when emulating +// those versions. +int main() +{ + int *ptr = 0; + int x; + + x = (int)ptr; + x = (short)ptr; + + return x; +} diff --git a/tests/tests/regressions/edg-28892-positive.sft.cpp b/tests/tests/regressions/edg-28892-positive.sft.cpp new file mode 100644 index 0000000000..70c82267ac --- /dev/null +++ b/tests/tests/regressions/edg-28892-positive.sft.cpp @@ -0,0 +1,6 @@ +//type:fp +//options_all:--c++20 +//options:--g++ --gnu_version=130300:--strict +using size_type = decltype(sizeof(0)); +static_assert(sizeof(size_type) >= sizeof(void*), "pointer width"); +size_type wide(void *p) { return reinterpret_cast(p); } diff --git a/tests/tests/regressions/edg-28892.sft.cpp b/tests/tests/regressions/edg-28892.sft.cpp new file mode 100644 index 0000000000..d022777a7b --- /dev/null +++ b/tests/tests/regressions/edg-28892.sft.cpp @@ -0,0 +1,11 @@ +//type:fn +//options_all:--c++20 +//options:--g++ --gnu_version=130300:--g++ --gnu_version=150200:--strict +// A pointer-to-integer reinterpret_cast requires sufficient destination width. +static_assert(sizeof(void*) > sizeof(unsigned char), "pointer width"); +unsigned char narrow_object(void *p) { + return reinterpret_cast(p); // Must be an error in GNU mode. +} +unsigned char narrow_function(void (*p)()) { + return reinterpret_cast(p); // Must also be an error. +}