Skip to content

Commit 8360528

Browse files
nv-cmeerwdaveedvdv-nvidia
authored andcommitted
Type transformations of qualified function types [GH edgcpp#335]
1 parent 7dc8173 commit 8360528

13 files changed

Lines changed: 157 additions & 12 deletions

File tree

‎src/Changes‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
Version 7.1
22

3+
10/21/26 [GH #335]
4+
Type transformations of qualified function types
5+
6+
Previously, the __add_lvalue_reference, __add_rvalue_reference, __add_pointer,
7+
and __decay intrinsics produced incorrect types for function types with cv- or
8+
ref-qualifiers. They now leave such types unchanged. For example, with
9+
--c++11:
10+
11+
using F = void() const;
12+
using F = __add_pointer(F); // Previously a spurious error, now okay.
13+
14+
315
10/19/26 [GH #218]
416
Reachability after a temporary with a "noreturn" constructor or destructor
517

‎src/types.c‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,6 +3580,22 @@ typeref entries representing typedefs or type operators.
35803580

35813581
#if !STANDALONE_UTILITY_PROGRAM
35823582

3583+
static a_type_ptr add_pointer_to_type(a_type_ptr tp)
3584+
/*
3585+
Apply the transformation corresponding to std::add_pointer_t to tp and return
3586+
the resulting type.
3587+
*/
3588+
{
3589+
if (is_referenceable_type(tp) || is_void_type(tp)) {
3590+
if (is_reference_type(tp)) {
3591+
tp = type_pointed_to(tp);
3592+
} /* if */
3593+
tp = make_pointer_type(tp);
3594+
} /* if */
3595+
return tp;
3596+
} /* add_pointer_to_type */
3597+
3598+
35833599
a_type_ptr apply_type_transforming_intrinsic(
35843600
a_type_ptr tp,
35853601
a_typeref_kind kind,
@@ -3641,10 +3657,7 @@ diagnostic in error cases. error_pos is the position to use for diagnostics
36413657
result = remove_qualifiers(tp, TQ_VOLATILE);
36423658
break;
36433659
case trk_add_pointer:
3644-
if (is_reference_type(tp)) {
3645-
tp = type_pointed_to(tp);
3646-
} /* if */
3647-
result = make_pointer_type(tp);
3660+
result = add_pointer_to_type(tp);
36483661
break;
36493662
case trk_remove_pointer:
36503663
if (is_pointer_type(tp)) {
@@ -3824,7 +3837,7 @@ Return TRUE if the given type is a referenceable type [defns.referenceable].
38243837
{
38253838
tp = skip_typerefs(tp);
38263839
return is_object_type(tp) || is_reference_ptr(tp) ||
3827-
(is_function(tp) && !is_qualified_type(tp));
3840+
(is_function(tp) && !is_qualified_function_type(tp));
38283841
} /* is_referenceable_type */
38293842

38303843

@@ -4080,7 +4093,7 @@ Apply the transformation corresponding to std::decay_t.
40804093
if (is_array_type(tp)) {
40814094
tp = make_pointer_type(array_element_type(tp));
40824095
} else if (is_function_type(tp)) {
4083-
tp = make_pointer_type(tp);
4096+
tp = add_pointer_to_type(tp);
40844097
} else {
40854098
tp = remove_qualifiers(tp, TQ_CONST | TQ_VOLATILE | TQ_RESTRICT);
40864099
} /* if */

‎tests/expectations/edg_x86_64/imported.log‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7339,7 +7339,6 @@ gnu/cpp/ext/constexpr-vla5.sft.cpp:fn:-DTEST_NUMBER=1 --c++11:FAIL:
73397339
gnu/cpp/ext/conv1.sft.cpp:fp:-DTEST_NUMBER=1 -w:FAIL:
73407340
gnu/cpp/ext/conv2.sft.cpp:fp:-DTEST_NUMBER=1 --c++11:FAIL:
73417341
gnu/cpp/ext/conv3.sft.cpp:fp:-DTEST_NUMBER=1:FAIL:
7342-
gnu/cpp/ext/decay.sft.cpp:fp:-DTEST_NUMBER=1 --c++11:FAIL:
73437342
gnu/cpp/ext/decay1.sft.cpp:fn:-DTEST_NUMBER=1 --c++11:FAIL:
73447343
gnu/cpp/ext/deprecate-1.sft.cpp:fp:-DTEST_NUMBER=1:FAIL:
73457344
gnu/cpp/ext/desig9.sft.cpp:fn:-DTEST_NUMBER=1:FAIL:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=1 --c++11 Test_name.c

‎tests/tests/changes/gh-335.sft.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//type:fp
2+
//options:--c++11
3+
//remark:[GH #335] Type transformations of qualified function types
4+
5+
using F = void() const;
6+
using F = __add_pointer(F); // Previously a spurious error, now okay.
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
fe_only -DTEST_NUMBER=1 --gnu_version=999999 -tused -e 200 --no_wrap --no_wrap_diagnostics --c++11 Test_name.c
2-
"Test_name.c", line 24: error: static assertion failed with "__is_same(test5_type, cfn_type)"
3-
SA(__is_same(test5_type, cfn_type));
4-
^
5-
6-
1 error detected in the compilation of "Test_name.c".
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=1 --c++11 Test_name.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=2 --c++17 Test_name.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=3 --gn 150200 --c++11 Test_name.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=4 --gn 150200 --c++17 Test_name.c

0 commit comments

Comments
 (0)