Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/pending_changes/edg-28967-deep-pointer-qualification.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[GH #455]
GNU C++ mode: unsafe qualification conversions of multilevel pointers

In GNU C++ mode (including Clang mode), an implicit conversion between
multilevel pointer types that adds const below the first level without adding
it at every intermediate level (e.g., "char **" to "const char **") was
accepted with a warning. Such a conversion is not const-safe and is not a
valid qualification conversion; GCC and Clang reject it. It is now an error.
Conversions through array levels that the qualification conversion check does
not handle in the emulated mode are still accepted with a warning. For
example, with --g++:

void f(char **p) {
const char **q = p; // Now an error.
}
43 changes: 43 additions & 0 deletions src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -11384,6 +11384,46 @@ conversion in C++/CLI because it drops gc-ness of an interior_ptr.

#endif /* MICROSOFT_EXTENSIONS_ALLOWED */


static a_boolean qualification_check_skips_arrays(a_type_ptr source_type,
a_type_ptr dest_type)
/*
Return TRUE if source_type or dest_type (the types pointed to by the two sides
of a pointer conversion) has an array type below some number of pointer and
pointer-to-member levels, and qualification_conversion_possible does not look
through array levels in the current mode (GNU C++ versions before 8.x and
Clang; see qualification_conversion_possible_full). In that case, a failed
qualification conversion check does not establish that a conversion that
adds qualifiers is unsafe.
*/
{
a_boolean result = FALSE;

if (gpp_version_is(<80000) || clang_mode) {
a_type_ptr tp;
int side;

for (side = 0; side < 2 && !result; side++) {
tp = side == 0 ? source_type : dest_type;
for (;;) {
tp = skip_typerefs(tp);
if (is_array(tp)) {
result = TRUE;
break;
} else if (is_pointer_or_handle(tp)) {
tp = type_pointed_to(tp);
} else if (is_ptr_to_member(tp)) {
tp = pm_member_type(tp);
} else {
break;
} /* if */
} /* for */
} /* for */
} /* if */
return result;
} /* qualification_check_skips_arrays */


a_boolean impl_pointer_conversion(
a_type_ptr source_type,
a_boolean source_is_constant,
Expand Down Expand Up @@ -11689,6 +11729,9 @@ operators), 3.3.15 (?: operator), and 3.3.16.1 (simple assignment).
std_conv->warning_suggested = warning_suggested;
qualifiers_checked = TRUE;
} else if ((!suppress_extensions || any_cfront_mode()) &&
(!gpp_mode ||
qualification_check_skips_arrays(source_type_pointed_to,
dest_type_pointed_to)) &&
same_type_with_added_qualifiers(
source_type_pointed_to,
dest_type_pointed_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,14 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const auto **fail2(p); // expected-error {{variable 'fail2' with type 'const auto **' has incompatible initializer of type 'int **'}}
^

"Test_name.c", line 60: warning: a value of type "int **" cannot be used to initialize an entity of type "const int **"
"Test_name.c", line 60: error: a value of type "int **" cannot be used to initialize an entity of type "const int **"
const auto **fail2(p); // expected-error {{variable 'fail2' with type 'const auto **' has incompatible initializer of type 'int **'}}
^

"Test_name.c", line 60: warning: variable "p" is used before its value is set
const auto **fail2(p); // expected-error {{variable 'fail2' with type 'const auto **' has incompatible initializer of type 'int **'}}
^

"Test_name.c", line 60: warning: variable "fail2" was declared but never referenced
const auto **fail2(p); // expected-error {{variable 'fail2' with type 'const auto **' has incompatible initializer of type 'int **'}}
^

"Test_name.c", line 70: warning: "auto" as a type specifier is nonstandard in this mode
auto p1 = &S::f;
^
Expand Down Expand Up @@ -123,4 +119,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
int (*funcptr2)(int) = funcptr;
^

4 errors detected in the compilation of "Test_name.c".
5 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
int *const *const &f2() { return p; }
^

"Test_name.c", line 261: warning: return value type does not match the function type
const int **const &f4() { return p; }
^

"Test_name.c", line 261: warning: returning reference to local temporary
"Test_name.c", line 261: error: return value type does not match the function type
const int **const &f4() { return p; }
^

Expand Down Expand Up @@ -59,4 +55,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A a;
^

10 errors detected in the compilation of "Test_name.c".
11 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ fe_only -DTEST_NUMBER=2 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
int *const *const &f2() { return p; }
^

"Test_name.c", line 261: warning: return value type does not match the function type
const int **const &f4() { return p; }
^

"Test_name.c", line 261: warning: returning reference to local temporary
"Test_name.c", line 261: error: return value type does not match the function type
const int **const &f4() { return p; }
^

Expand Down Expand Up @@ -92,4 +88,4 @@ fe_only -DTEST_NUMBER=2 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A a;
^

14 errors detected in the compilation of "Test_name.c".
15 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ fe_only -DTEST_NUMBER=3 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
int *const *const &f2() { return p; }
^

"Test_name.c", line 261: warning: return value type does not match the function type
const int **const &f4() { return p; }
^

"Test_name.c", line 261: warning: returning reference to local temporary
"Test_name.c", line 261: error: return value type does not match the function type
const int **const &f4() { return p; }
^

Expand Down Expand Up @@ -96,4 +92,4 @@ fe_only -DTEST_NUMBER=3 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A a;
^

15 errors detected in the compilation of "Test_name.c".
16 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ fe_only -DTEST_NUMBER=4 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
int *const *const &f2() { return p; }
^

"Test_name.c", line 261: warning: return value type does not match the function type
const int **const &f4() { return p; }
^

"Test_name.c", line 261: warning: returning reference to local temporary
"Test_name.c", line 261: error: return value type does not match the function type
const int **const &f4() { return p; }
^

Expand Down Expand Up @@ -102,4 +98,4 @@ fe_only -DTEST_NUMBER=4 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A a;
^

17 errors detected in the compilation of "Test_name.c".
18 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ fe_only -DTEST_NUMBER=5 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
int *const *const &f2() { return p; }
^

"Test_name.c", line 261: warning: return value type does not match the function type
const int **const &f4() { return p; }
^

"Test_name.c", line 261: warning: returning reference to local temporary
"Test_name.c", line 261: error: return value type does not match the function type
const int **const &f4() { return p; }
^

Expand Down Expand Up @@ -152,4 +148,4 @@ fe_only -DTEST_NUMBER=5 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A a;
^

20 errors detected in the compilation of "Test_name.c".
21 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ fe_only -DTEST_NUMBER=6 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
int *const *const &f2() { return p; }
^

"Test_name.c", line 261: warning: return value type does not match the function type
const int **const &f4() { return p; }
^

"Test_name.c", line 261: warning: returning reference to local temporary
"Test_name.c", line 261: error: return value type does not match the function type
const int **const &f4() { return p; }
^

Expand Down Expand Up @@ -152,4 +148,4 @@ fe_only -DTEST_NUMBER=6 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A a;
^

20 errors detected in the compilation of "Test_name.c".
21 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ fe_only -DTEST_NUMBER=7 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
int *const *const &f2() { return p; }
^

"Test_name.c", line 261: warning: return value type does not match the function type
const int **const &f4() { return p; }
^

"Test_name.c", line 261: warning: returning reference to local temporary
"Test_name.c", line 261: error: return value type does not match the function type
const int **const &f4() { return p; }
^

Expand Down Expand Up @@ -152,4 +148,4 @@ fe_only -DTEST_NUMBER=7 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A a;
^

20 errors detected in the compilation of "Test_name.c".
21 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -849,4 +849,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A b(a);
^

154 errors detected in the compilation of "Test_name.c".
155 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ fe_only -DTEST_NUMBER=2 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -831,4 +831,4 @@ fe_only -DTEST_NUMBER=2 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

155 errors detected in the compilation of "Test_name.c".
156 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ fe_only -DTEST_NUMBER=3 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -823,4 +823,4 @@ fe_only -DTEST_NUMBER=3 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

155 errors detected in the compilation of "Test_name.c".
156 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ fe_only -DTEST_NUMBER=4 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -819,4 +819,4 @@ fe_only -DTEST_NUMBER=4 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

155 errors detected in the compilation of "Test_name.c".
156 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ fe_only -DTEST_NUMBER=5 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -819,4 +819,4 @@ fe_only -DTEST_NUMBER=5 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

156 errors detected in the compilation of "Test_name.c".
157 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ fe_only -DTEST_NUMBER=6 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -819,4 +819,4 @@ fe_only -DTEST_NUMBER=6 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

156 errors detected in the compilation of "Test_name.c".
157 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ fe_only -DTEST_NUMBER=7 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -819,4 +819,4 @@ fe_only -DTEST_NUMBER=7 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

156 errors detected in the compilation of "Test_name.c".
157 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -849,4 +849,4 @@ fe_only -DTEST_NUMBER=1 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
const A b(a);
^

153 errors detected in the compilation of "Test_name.c".
154 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ fe_only -DTEST_NUMBER=2 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -831,4 +831,4 @@ fe_only -DTEST_NUMBER=2 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

154 errors detected in the compilation of "Test_name.c".
155 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ fe_only -DTEST_NUMBER=3 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -823,4 +823,4 @@ fe_only -DTEST_NUMBER=3 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

154 errors detected in the compilation of "Test_name.c".
155 errors detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ fe_only -DTEST_NUMBER=4 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
^
detected during instantiation of "void cwg345::f(T) [with T=cwg345::A]" at line 753

"Test_name.c", line 787: warning: return value type does not match the function type
"Test_name.c", line 787: error: return value type does not match the function type
return p;
^
detected during instantiation of "cwg349::A::operator T ***() [with T=const int]" at line 796
Expand Down Expand Up @@ -819,4 +819,4 @@ fe_only -DTEST_NUMBER=4 --clang -tused -e 200 --no_wrap_diagnostics --clang_vers
extern WithoutLinkage5 withoutLinkage5;
^

154 errors detected in the compilation of "Test_name.c".
155 errors detected in the compilation of "Test_name.c".
Loading
Loading