Age | Commit message (Collapse) | Author | Files | Lines |
|
Here when resolving the implicit object for '&wrapped' within the
local class Foo, we expect to obtain a dummy object of type Foo& since
there's no 'this' available in this context. And yet at this point
current_class_ref still corresponds to the outer class Context (and is
const), which confuses maybe_dummy_object into propagating the cv-quals
of current_class_ref and returning an object of type const Foo&. Thus
decltype(&wrapped) wrongly yields const int* instead of int*.
The problem ultimately seems to be that the 'this' from the enclosing
class appears available for use when parsing the local class, but 'this'
shouldn't persist across classes like that. This patch fixes this by
clearing current_class_ptr/ref before parsing a class definition.
After this change, for the test name-clash11.C in C++98 mode we would
now complain about an invalid use of 'this' in e.g.
ASSERT (sizeof (this->A) == 16);
due to the way the test defines the ASSERT macro via a local class.
This patch redefines the macro using a local typedef instead.
PR c++/106969
gcc/cp/ChangeLog:
* parser.cc (cp_parser_class_specifier): Clear current_class_ptr
and current_class_ref sooner, before parsing a class definition.
gcc/testsuite/ChangeLog:
* g++.dg/lookup/name-clash11.C: Fix ASSERT macro definition in
C++98 mode.
* g++.dg/lookup/this2.C: New test.
|
|
The default argument code in type_unification_real was assuming that all
targs we've deduced by that point are non-dependent, but that's not the case
for partial ordering.
PR c++/105481
gcc/cp/ChangeLog:
* pt.cc (type_unification_real): Adjust for partial ordering.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/fntmpdefarg-partial1.C: New test.
|
|
|
|
Here, we were calling build_reinterpret_cast regardless of whether there was
actually a cast, and that now sets REINTERPRET_CAST_P. But that
optimization seems dodgy anyway, as it involves NOP_EXPR from one
RECORD_TYPE to another and we try to reserve NOP_EXPR for fundamental types.
And the generated code seems the same, so let's drop it. And also strip
location wrappers.
PR c++/105996
gcc/cp/ChangeLog:
* typeck.cc (build_ptrmemfunc): Drop 0-offset optimization
and location wrappers.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-pmf3.C: New test.
|
|
Based on <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107532#c24>,
it seems like we should treat *any* class with a reference member
as a reference wrapper. To suppress the warning in
int i = 42;
auto const& v = std::get<0>(std::tuple<int&>(i));
we have to look into base classes as well. For std::tuple, this means
that we have to check the _Head_base subobject, which is a non-direct
base class of std::tuple. So I've employed a DFS walk.
PR c++/107532
gcc/cp/ChangeLog:
* call.cc (class_has_reference_member_p): New.
(class_has_reference_member_p_r): New.
(reference_like_class_p): Don't look for a specific constructor.
Use a DFS walk with class_has_reference_member_p_r.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wdangling-reference11.C: New test.
* g++.dg/warn/Wdangling-reference12.C: New test.
|
|
In this testcase, the tree walk to look for bare parameter packs was
confused by finding a type with no TREE_BINFO. But it should be fine that
it's unset; we already checked for unexpanded packs at parse time.
I also tried doing the partial instantiation of the local class, which is
probably the long-term direction we want to go, but for stage 4 let's go
with this safer change.
PR c++/109241
gcc/cp/ChangeLog:
* pt.cc (find_parameter_packs_r): Handle null TREE_BINFO.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/lambda-generic-local-class2.C: New test.
|
|
|
|
fold_convert doesn't work with a dependent argument, and problematically
differed from the corresponding fold+build_nop further down in the
function. So change it to match.
PR c++/108390
gcc/cp/ChangeLog:
* pt.cc (unify): Use fold of build_nop instead of fold_convert.
gcc/testsuite/ChangeLog:
* g++.dg/template/partial-order3.C: New test.
|
|
Since r7-2549 we were throwing away the explicit C:: when we found that ~C
has an attribute that we treat as making its type dependent.
PR c++/108795
gcc/cp/ChangeLog:
* semantics.cc (finish_id_expression_1): Check scope before
returning id_expression.
gcc/testsuite/ChangeLog:
* g++.dg/ext/attr-tsafe1.C: New test.
|
|
As the PR shows, we currently emit duplicate diagnostics for calls to
functions marked with __attribute__((unavailable)). This patch fixes
that.
gcc/cp/ChangeLog:
PR c++/109177
* call.cc (build_over_call): Use make_temp_override to suppress
both unavailable and deprecated warnings when calling
build_addr_func.
gcc/testsuite/ChangeLog:
PR c++/109177
* g++.dg/ext/pr109177.C: New test.
|
|
|
|
When parsing a default member init we just build a CONVERT_EXPR for
converting to a virtual base, and then expand that into the more complex
form when we actually use the DMI in a constructor. But that wasn't working
for the template case where we are considering the conversion at the point
that the constructor needs the DMI instantiation, so it seemed like we were
in a constructor already. And then when the other constructor tries to
reuse the instantiation, it sees uses of the first constructor's parameters,
and dies. So ensure that we get the CONVERT_EXPR in this case, too.
PR c++/106890
gcc/cp/ChangeLog:
* init.cc (maybe_instantiate_nsdmi_init): Don't leave
current_function_decl set to a constructor.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/nsdmi-template25.C: New test.
|
|
|
|
When I implemented explicit(bool) in r9-3735, I added this code to
add_template_candidate_real:
+ /* Now the explicit specifier might have been deduced; check if this
+ declaration is explicit. If it is and we're ignoring non-converting
+ constructors, don't add this function to the set of candidates. */
+ if ((flags & LOOKUP_ONLYCONVERTING) && DECL_NONCONVERTING_P (fn))
+ return NULL;
but as this test demonstrates, that's incorrect when we're initializing
from a {}: for list-initialization we consider explicit constructors and
complain if one is chosen.
PR c++/109159
gcc/cp/ChangeLog:
* call.cc (add_template_candidate_real): Add explicit decls to the
set of candidates when the initializer is a braced-init-list.
libstdc++-v3/ChangeLog:
* testsuite/20_util/pair/cons/explicit_construct.cc: Adjust dg-error.
* testsuite/20_util/tuple/cons/explicit_construct.cc: Likewise.
* testsuite/23_containers/span/explicit.cc: Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/explicit16.C: New test.
|
|
The following two testcases are miscompiled, because we keep TREE_READONLY
on the vars even when they are (possibly) dynamically initialized by a TLS
wrapper function. Normally cp_finish_decl drops TREE_READONLY from vars
which need dynamic initialization, but for TLS we do this kind of
initialization upon every access to those variables. Keeping them
TREE_READONLY means e.g. PRE can hoist loads from those before loops
which contain the TLS wrapper calls, so we can access the TLS variables
before they are initialized.
2023-03-20 Jakub Jelinek <jakub@redhat.com>
PR c++/109164
* cp-tree.h (var_needs_tls_wrapper): Declare.
* decl2.cc (var_needs_tls_wrapper): No longer static.
* decl.cc (cp_finish_decl): Clear TREE_READONLY on TLS variables
for which a TLS wrapper will be needed.
* g++.dg/tls/thread_local13.C: New test.
* g++.dg/tls/thread_local13-aux.cc: New file.
* g++.dg/tls/thread_local14.C: New test.
* g++.dg/tls/thread_local14-aux.cc: New file.
|
|
|
|
When a lambda refers to a constant local variable in the enclosing scope, we
tentatively capture it, but if we end up pulling out its constant value, we
go back at the end of the lambda and prune any unneeded captures. Here
while parsing the template we decided that the dim capture was unneeded,
because we folded it away, but then we brought back the use in the template
trees that try to preserve the source representation with added type info.
So then when we tried to instantiate that use, we couldn't find what it was
trying to use, and crashed.
Fixed by not trying to prune when parsing a template; we'll prune at
instantiation time.
PR c++/108975
gcc/cp/ChangeLog:
* lambda.cc (prune_lambda_captures): Don't bother in a template.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/lambda/lambda-const11.C: New test.
|
|
Since we aren't going through the normal call machinery, we need to check
the dtor access specifically.
PR c++/109172
gcc/cp/ChangeLog:
* except.cc (build_throw): Check dtor access.
gcc/testsuite/ChangeLog:
* g++.dg/eh/dtor4.C: New test.
|
|
do_friend was only considering class-qualified identifiers for the
qualified-id case, but we also need to skip local scope when there's an
explicit namespace scope.
PR c++/69410
gcc/cp/ChangeLog:
* friend.cc (do_friend): Handle namespace as scope argument.
* decl.cc (grokdeclarator): Pass down in_namespace.
gcc/testsuite/ChangeLog:
* g++.dg/lookup/friend24.C: New test.
|
|
|
|
As in 108242, we need to instantiate in the context of the enclosing
function, not after it's gone.
PR c++/105809
gcc/cp/ChangeLog:
* init.cc (get_nsdmi): Split out...
(maybe_instantiate_nsdmi_init): ...this function.
* cp-tree.h: Declare it.
* pt.cc (tsubst_expr): Use it.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-__func__3.C: New test.
|
|
Here we are trying to do name lookup in a deferred instantiation of t() and
failing to find __func__. tsubst_expr already tries to instantiate members
of local classes, but was failing with the partial instantiation of generic
lambdas.
PR c++/108242
gcc/cp/ChangeLog:
* pt.cc (tsubst_expr) [TAG_DEFN]: Handle partial instantiation.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/lambda-generic-func2.C: New test.
|
|
We don't want to call build_offset_ref with an enum.
PR c++/101869
gcc/cp/ChangeLog:
* semantics.cc (finish_qualified_id_expr): Don't try to build a
pointer-to-member if the scope is an enumeration.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/enum43.C: New test.
|
|
This testcase in this PR (already fixed by r13-6526-ge4692319fd5fc7)
demonstrates that maybe_constant_init can be called on an unevaluated
operand (e.g. from massage_init_elt) so this entry point should also
limit constant evaluation in that case, like maybe_constant_value does.
PR c++/109030
gcc/cp/ChangeLog:
* constexpr.cc (maybe_constant_init_1): For an unevaluated
non-manifestly-constant operand, don't constant evaluate
and instead call fold_to_constant as in maybe_constant_value.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-inst2.C: New test.
|
|
When satisfaction_cache::get detects constraint recursion, it asserts
that entry->result is empty. This makes sense when we're initially
detecting/diagnosing recursion from the inner recursive call, but
afterwards from the outer recursive call the recursion error is treated
like any other unrelated constraint failure encountered during
satisfaction, and we set entry->result to whatever the satisfaction
value ended up being.
Perhaps we should keep entry->result cleared in this case, but that'd
require the inner recursive call to communicate to the outer recursive
call that constraint recursion occurred, likely via setting entry->result
to some sentinel value, which doesn't seem to be worth the complexity.
So this patch just relaxes the problematic assert to accept non-empty
entry->result as long as we've already issued an error.
PR c++/100288
gcc/cp/ChangeLog:
* constraint.cc (satisfaction_cache::get): Relax overly strict
checking assert in the constraint recursion case.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-recursive-sat5.C: New test.
|
|
Here we were building a temporary MoveOnlyAwaitable to hold the result of
evaluating 'o', but since 'o' is an lvalue we should build a reference
instead.
PR c++/105406
gcc/cp/ChangeLog:
* coroutines.cc (build_co_await): Handle lvalue 'o'.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/co-await-moveonly1.C: New test.
|
|
|
|
When flatten_await_stmt processes the backing array for an initializer_list,
we call cp_build_modify_expr to initialize the promoted variable from the
TARGET_EXPR; that needs to be accepted.
PR c++/103871
PR c++/98056
gcc/cp/ChangeLog:
* typeck.cc (cp_build_modify_expr): Allow array initialization of
DECL_ARTIFICIAL variable.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/co-await-initlist1.C: New test.
|
|
We crash here since r10-3661, the store_init_value hunk in particular.
Before, we called cp_fully_fold_init, so e.g.
{.str=VIEW_CONVERT_EXPR<char[8]>("")}
was folded into
{.str=""}
but now we don't fold and keep the VCE around, and it causes trouble in
cxx_eval_store_expression: in the !refs->is_empty () loop we descend on
.str's initializer but since it's wrapped in a VCE, we skip the STRING_CST
check and then crash on the CONSTRUCTOR_NO_CLEARING.
PR c++/107280
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_store_expression): Strip location wrappers.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/constexpr-lambda28.C: New test.
|
|
This function needs to handle this case like convert_template_argument.
PR c++/58538
gcc/cp/ChangeLog:
* semantics.cc (check_template_template_default_arg): Check
maybe_get_template_decl_from_type_decl.
gcc/testsuite/ChangeLog:
* g++.dg/template/ttp7.C: Remove expected error.
|
|
I kept trying to improve our choice of how many levels of outer_args to add,
when really the problem was that outer_args are for PARM and for this
reverse deduction we should be adding the outer arguments for ARG.
I spent quite a while trying to get DECL_CONTEXT set consistently on
template template parameters that have gone through
reduce_template_parm_level before I realized I could just use
current_scope().
PR c++/108179
PR c++/104107
PR c++/95036
gcc/cp/ChangeLog:
* pt.cc (coerce_template_template_parms): Use args from
DECL_CONTEXT (arg_tmpl) instead of outer_args.
gcc/testsuite/ChangeLog:
* g++.dg/template/ttp35.C: New test.
|
|
This should have no semantic effect, but is a prerequisite for the PR108179
fix to follow.
PR c++/108179
gcc/cp/ChangeLog:
* pt.cc (coerce_template_template_parms): Take the arg and parm
templates directly.
(coerce_template_template_parm): Adjust.
(template_template_parm_bindings_ok_p): Adjust.
(convert_template_argument): Adjust.
|
|
|
|
An out-of-line definition of a member of a constrained class template
needs to repeat the template's constraints, but it turns out we don't
verify anywhere that the two sets of constraints match. This patch
adds such a check to push_template_decl, nearby a similar consistency
check for the template parameter list lengths.
PR c++/96830
gcc/cp/ChangeLog:
* pt.cc (push_inline_template_parms_recursive): Set
TEMPLATE_PARMS_CONSTRAINTS.
(push_template_decl): For an out-of-line declaration, verify
constraints for each enclosing template scope match those of the
original template declaratation.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-class5.C: New test.
* g++.dg/cpp2a/concepts-class5a.C: New test.
|
|
When instantiating a constrained template friend naming an already
declared class template, tsubst_friend_class erroneously passes to
redeclare_class_template the existing template's constraints instead of
those of the friend declaration, which causes the constraint comparison
check therein to trivially succeed and we fail to diagnose legitimate
constraint mismatches.
PR c++/96830
gcc/cp/ChangeLog:
* pt.cc (redeclare_class_template): Add missing "of" in
constraint mismatch diagnostic.
(tsubst_friend_class): For an already declared class template,
substitute and pass the friend declaration's constraints to
redeclare_class_template instead of passing the existing
template's constraints.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-friend14.C: New test.
|
|
Generally we expect TPARMS_PRIMARY_TEMPLATE to be set, but sometimes it
isn't for partial instantiations. This ought to be improved, but it's
trivial to work around it in this case.
PR c++/108468
gcc/cp/ChangeLog:
* pt.cc (unify_pack_expansion): Check that TPARMS_PRIMARY_TEMPLATE
is non-null.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ78.C: New test.
|
|
I removed this folding in GCC 12 because it was interfering with an
experiment of richi's, but that never went in and the change causes
regressions, so let's put it back.
This reverts commit r12-5638-ga3e75c1491cd2d.
PR c++/107310
gcc/cp/ChangeLog:
* cp-gimplify.cc (genericize_if_stmt): Restore folding
of constant conditions.
gcc/testsuite/ChangeLog:
* c-c++-common/Wimplicit-fallthrough-39.c: Adjust warning.
* g++.dg/warn/Wreturn-6.C: New test.
|
|
__has_unique_object_representations [PR109096]
As reported in the PR, for __has_unique_object_representations we
were treating unnamed bitfields as named ones, which is wrong, they
are actually padding.
THe following patch fixes that.
2023-03-14 Jakub Jelinek <jakub@redhat.com>
PR c++/109096
* tree.cc (record_has_unique_obj_representations): Ignore unnamed
bitfields.
* g++.dg/cpp1z/has-unique-obj-representations3.C: New test.
|
|
|
|
It's been inconvenient to compile testcases preprocessed with GCC 12 or
earlier because they break on
typedef __float128 _Float128;
We already had code for handling this with bool and wchar_t, it just needs
to be extended to _FloatNN as well.
PR c++/107128
gcc/cp/ChangeLog:
* parser.cc (cp_parser_set_decl_spec_type): Use
redefined_builtin_type for extended_float_type_p.
gcc/testsuite/ChangeLog:
* g++.dg/warn/pragma-system_header6.h: New test.
* g++.dg/warn/pragma-system_header6.C: New test.
|
|
std::span is a view and therefore should be treated as a reference
wrapper class for the purposes of -Wdangling-reference. I'm not sure
there's a pattern that we could check for.
PR c++/107532
gcc/cp/ChangeLog:
* call.cc (reference_like_class_p): Check for std::span.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wdangling-reference10.C: New test.
|
|
|
|
[PR107558]
The following testcase ICEs, because OpenMP lowering for shared clause
on l variable with REFERENCE_TYPE creates POINTER_TYPE to REFERENCE_TYPE.
The reason is that the automatic variable has non-trivial construction
(reference to a lambda) and -fmerge-all-constants is on and so TREE_READONLY
isn't set - omp-low will handle automatic TREE_READONLY vars in shared
specially and only copy to the construct and not back, while !TREE_READONLY
are assumed to be changeable.
The PR91529 change rationale was that the gimplification can change
some non-addressable automatic variables to TREE_STATIC with
-fmerge-all-constants and therefore TREE_READONLY on them is undesirable.
But, the gimplifier does that only for aggregate variables:
switch (TREE_CODE (type))
{
case RECORD_TYPE:
case UNION_TYPE:
case QUAL_UNION_TYPE:
case ARRAY_TYPE:
and not for anything else. So, I think clearing TREE_READONLY for
automatic integral or reference or pointer etc. vars for
-fmerge-all-constants only is unnecessary.
2023-03-10 Jakub Jelinek <jakub@redhat.com>
PR c++/107558
* decl.cc (cp_finish_decl): Don't clear TREE_READONLY on
automatic non-aggregate variables just because of
-fmerge-all-constants.
* g++.dg/gomp/pr107558.C: New test.
|
|
The following testcase FAILs, because starting with r12-6028
the S class has only 2 bytes, not enough to hold one 7-bit bitfield, one 8-bit
bitfield and one 8-bit char field.
The reason is that when end_of_class attempts to compute dsize, it simply
adds byte_position of the field and DECL_SIZE_UNIT (and uses maximum from
those offsets).
The problematic bit-field in question has bit_position 7, byte_position 0,
DECL_SIZE 8 and DECL_SIZE_UNIT 1. So, byte_position + DECL_SIZE_UNIT is
1, even when the bitfield only has a single bit in the first byte and 7
further bits in the second byte, so per the Itanium ABI it should be 2:
"In either case, update dsize(C) to include the last byte
containing (part of) the bit-field, and update sizeof(C) to
max(sizeof(C),dsize(C))."
The following patch fixes it by computing bitsize of the end and using
CEIL_DIV_EXPR division to round it to next byte boundary and convert
from bits to bytes.
While this is an ABI change, classes with such incorrect layout couldn't
have worked properly, so I doubt anybody is actually running it often
in the wild. Thus I think adding some ABI warning for it is unnecessary.
2023-03-10 Jakub Jelinek <jakub@redhat.com>
PR c++/109039
* class.cc (end_of_class): For bit-fields, instead of computing
offset as sum of byte_position (field) and DECL_SIZE_UNIT (field),
compute it as sum of bit_position (field) and DECL_SIZE (field)
divided by BITS_PER_UNIT rounded up.
* g++.dg/abi/no_unique_address7.C: New test.
|
|
Better not to ICE after various valid errors.
PR c++/108972
gcc/cp/ChangeLog:
* lambda.cc (compare_lambda_template_head): Check more
for error_mark_node.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-lambda3.C: Run at lower std levels,
but expect errors.
|
|
We were failing to come up with the name for the anonymous union. It seems
like unfortunate redundancy, but the ABI does say that the name of an
anonymous union is its first named member.
PR c++/108566
gcc/cp/ChangeLog:
* mangle.cc (anon_aggr_naming_decl): New.
(write_unqualified_name): Use it.
gcc/testsuite/ChangeLog:
* g++.dg/abi/anon6.C: New test.
|
|
On the following testcase, we warn with -Wunused-value twice, once
in the FEs and later on cgraphunit again with slightly different
wording.
The following patch fixes that by registering a warning suppression in the
FEs when we warn and not warning in cgraphunit anymore if that happened.
2023-03-10 Jakub Jelinek <jakub@redhat.com>
PR c/108079
gcc/
* cgraphunit.cc (check_global_declaration): Don't warn for unused
variables which have OPT_Wunused_variable warning suppressed.
gcc/c/
* c-decl.cc (pop_scope): Suppress OPT_Wunused_variable warning
after diagnosing it.
gcc/cp/
* decl.cc (poplevel): Suppress OPT_Wunused_variable warning
after diagnosing it.
gcc/testsuite/
* c-c++-common/Wunused-var-18.c: New test.
|
|
The code for handling signed + typedef was breaking on __int128_t, because
it isn't a proper typedef: it doesn't have DECL_ORIGINAL_TYPE.
PR c++/108099
gcc/cp/ChangeLog:
* decl.cc (grokdeclarator): Handle non-typedef typedef_decl.
gcc/testsuite/ChangeLog:
* g++.dg/ext/int128-7.C: New test.
|
|
PR c++/108542
gcc/cp/ChangeLog:
* class.cc (instantiate_type): Strip location wrapper.
gcc/testsuite/ChangeLog:
* g++.dg/contracts/contracts-err1.C: New test.
|
|
|