From patchwork Wed Dec 7 21:50:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1713468 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=p9JNLLDm; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NS9w63dwrz23yq for ; Thu, 8 Dec 2022 08:51:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8B35383B694 for ; Wed, 7 Dec 2022 21:51:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8B35383B694 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670449871; bh=y+dpG6mmhneCDXx6rsHwlVwcQh3ckP7iwbEROOTK4OA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=p9JNLLDm6OswBsig/+NzV/k62hvyjdnd+GiW11oISF84kGgVatnlhVEv1nPpJgqBL 2iqBuHgZiyto/gJtM5QVqB8tf4vT+jgmHYXZrT7CVp+QUZUNiSEN5lamKsvJYi9jPk D7hh8pQRMcPX+1vAP/c71LJtueOx5qojwIgk3RV8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D3A673850B37 for ; Wed, 7 Dec 2022 21:50:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3A673850B37 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-612--MYX6KoFOdO7vkEgqj3_YA-1; Wed, 07 Dec 2022 16:50:32 -0500 X-MC-Unique: -MYX6KoFOdO7vkEgqj3_YA-1 Received: by mail-qv1-f72.google.com with SMTP id on28-20020a056214449c00b004bbf12d7976so37944952qvb.18 for ; Wed, 07 Dec 2022 13:50:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=y+dpG6mmhneCDXx6rsHwlVwcQh3ckP7iwbEROOTK4OA=; b=f2NQ+uRMzeXCapdXVmfQpbN8JVJ9zxj2YgWZI3tHIn4hEsV0rkvUG2oVMgJazXM3uf 8QiFDPhOzj8axzZK4I//QyZAXOx+ySa3aKltWTzT/L0vBACtBTlhg1U4oES00B+kEQe8 UBfSOy2BO8ebRVqjRLinzuRqnZ2Xzakmo0lnTKU0Dl4R+0RQeW/UZtmuaClfNsg46nxq JxYYmjbYDprvZ2KTcqJewj/Xd4jwBiLFTsrZxht2TV6uqQS985D9QuDTFv+0SFX5TD+j 2AbnW3EU/faiDP5H1EbYcGEaMWdg51yWxwGxo6TlFY3wXt/vun+wgBFCBEcdAEfugb9i OOrA== X-Gm-Message-State: ANoB5pkOMatnLFfvqxfzt5eV7O5d419qV7FAX2XlK/r4lP9KU8cs+250 MgWgCR+U8b8NTvhq2VjegDwAo9MDMwEQQLUww+DVl+sFgpEOokEN3tCzV/3Ic+UhKnkzsCOEw5h mxWNHJT+dPNc47gAU50E05u5js1aO4fKElQX5hlaqa4Ty/9BIsRXS9LEBKlQ1qELVZ3Q= X-Received: by 2002:a05:622a:1245:b0:3a5:8445:e1a6 with SMTP id z5-20020a05622a124500b003a58445e1a6mr68504128qtx.301.1670449831330; Wed, 07 Dec 2022 13:50:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf42OA7s/6pTaPm3VEGQhmwQ1/5iY+poAkAFUZnfDHtlHZ/aQZ8CkxmIbH7HpKGgHem0jP/YPA== X-Received: by 2002:a05:622a:1245:b0:3a5:8445:e1a6 with SMTP id z5-20020a05622a124500b003a58445e1a6mr68504103qtx.301.1670449830835; Wed, 07 Dec 2022 13:50:30 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id q13-20020a05620a0d8d00b006fab416015csm18066201qkl.25.2022.12.07.13.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 13:50:30 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, Patrick Palka Subject: [PATCH] c++: modules and std::source_location::current() def arg [PR100881] Date: Wed, 7 Dec 2022 16:50:28 -0500 Message-Id: <20221207215028.1851790-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" We currently declare __builtin_source_location with a const void* return type instead of the true type (const std::source_location::__impl*), and later when folding this builtin we just obtain the true type via name lookup. But the below testcase demonstrates this name lookup approach seems to interact poorly with modules, since we may import an entity that uses std::source_location::current() in a default argument (or DMI) without also importing , and thus the name lookup will fail when folding the builtin at the call site unless we also import . This patch fixes by instead initially declaring __builtin_source_location with an auto return type and updating it appropriately upon its first use. Thus when folding calls to this builtin we can fish out the true return type through the type of the CALL_EXPR and avoid needing to do name lookup. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look reasonable? PR c++/100881 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_builtin_function_call): Adjust calls to fold_builtin_source_location. * cp-gimplify.cc (cp_gimplify_expr): Likewise. (cp_fold): Likewise. (get_source_location_impl_type): Remove location_t parameter and adjust accordingly. No longer static. (fold_builtin_source_location): Take a CALL_EXPR tree instead of a location and obtain the impl type from its return type. * cp-tree.h (enum cp_tree_index): Remove CPTI_SOURCE_LOCATION_IMPL enumerator. (source_location_impl): Remove. (fold_builtin_source_location): Adjust parameter type. (get_source_location_impl_type): Declare. * decl.cc (cxx_init_decl_processing): Declare __builtin_source_location with auto return type instead of const void*. (require_deduced_type): Update the return type of __builtin_source_location. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/srcloc3.C: Adjust expected note s/evaluating/using. * g++.dg/cpp2a/srcloc4.C: Likewise. * g++.dg/cpp2a/srcloc5.C: Likewise. * g++.dg/cpp2a/srcloc6.C: Likewise. * g++.dg/cpp2a/srcloc7.C: Likewise. * g++.dg/cpp2a/srcloc8.C: Likewise. * g++.dg/cpp2a/srcloc9.C: Likewise. * g++.dg/cpp2a/srcloc10.C: Likewise. * g++.dg/cpp2a/srcloc11.C: Likewise. * g++.dg/cpp2a/srcloc12.C: Likewise. * g++.dg/cpp2a/srcloc13.C: Likewise. * g++.dg/modules/pr100881_a.C: New test. * g++.dg/modules/pr100881_b.C: New test. --- gcc/cp/constexpr.cc | 2 +- gcc/cp/cp-gimplify.cc | 58 +++++++++++------------ gcc/cp/cp-tree.h | 8 +--- gcc/cp/decl.cc | 25 +++++++++- gcc/testsuite/g++.dg/cpp2a/srcloc10.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc11.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc12.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc13.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc3.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc4.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc5.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc6.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc7.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc8.C | 2 +- gcc/testsuite/g++.dg/cpp2a/srcloc9.C | 2 +- gcc/testsuite/g++.dg/modules/pr100881_a.C | 28 +++++++++++ gcc/testsuite/g++.dg/modules/pr100881_b.C | 8 ++++ 17 files changed, 101 insertions(+), 50 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr100881_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr100881_b.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 0b43ae4ece3..6ff994fd599 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -1492,7 +1492,7 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun, temp_override ovr (current_function_decl); if (ctx->call && ctx->call->fundef) current_function_decl = ctx->call->fundef->decl; - return fold_builtin_source_location (EXPR_LOCATION (t)); + return fold_builtin_source_location (t); } int strops = 0; diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 983f2a566a6..6ad8458ab28 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -722,7 +722,7 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) break; case CP_BUILT_IN_SOURCE_LOCATION: *expr_p - = fold_builtin_source_location (EXPR_LOCATION (*expr_p)); + = fold_builtin_source_location (*expr_p); break; case CP_BUILT_IN_IS_CORRESPONDING_MEMBER: *expr_p @@ -2850,7 +2850,7 @@ cp_fold (tree x) case CP_BUILT_IN_IS_CONSTANT_EVALUATED: break; case CP_BUILT_IN_SOURCE_LOCATION: - x = fold_builtin_source_location (EXPR_LOCATION (x)); + x = fold_builtin_source_location (x); break; case CP_BUILT_IN_IS_CORRESPONDING_MEMBER: x = fold_builtin_is_corresponding_member @@ -2872,7 +2872,7 @@ cp_fold (tree x) && fndecl_built_in_p (callee, CP_BUILT_IN_SOURCE_LOCATION, BUILT_IN_FRONTEND)) { - x = fold_builtin_source_location (EXPR_LOCATION (x)); + x = fold_builtin_source_location (x); break; } @@ -3171,12 +3171,11 @@ process_stmt_assume_attribute (tree std_attrs, tree statement, return remove_attribute ("gnu", "assume", std_attrs); } -/* Helper of fold_builtin_source_location, return the - std::source_location::__impl type after performing verification - on it. LOC is used for reporting any errors. */ +/* Return the type std::source_location::__impl after performing verification + on it. */ -static tree -get_source_location_impl_type (location_t loc) +tree +get_source_location_impl_type () { tree name = get_identifier ("source_location"); tree decl = lookup_qualified_name (std_node, name); @@ -3184,9 +3183,9 @@ get_source_location_impl_type (location_t loc) { auto_diagnostic_group d; if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST) - qualified_name_lookup_error (std_node, name, decl, loc); + qualified_name_lookup_error (std_node, name, decl, input_location); else - error_at (loc, "%qD is not a type", decl); + error ("%qD is not a type", decl); return error_mark_node; } name = get_identifier ("__impl"); @@ -3196,15 +3195,15 @@ get_source_location_impl_type (location_t loc) { auto_diagnostic_group d; if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST) - qualified_name_lookup_error (type, name, decl, loc); + qualified_name_lookup_error (type, name, decl, input_location); else - error_at (loc, "%qD is not a type", decl); + error ("%qD is not a type", decl); return error_mark_node; } type = TREE_TYPE (decl); if (TREE_CODE (type) != RECORD_TYPE) { - error_at (loc, "%qD is not a class type", decl); + error ("%qD is not a class type", decl); return error_mark_node; } @@ -3221,8 +3220,7 @@ get_source_location_impl_type (location_t loc) { if (TREE_TYPE (field) != const_string_type_node) { - error_at (loc, "%qD does not have % type", - field); + error ("%qD does not have % type", field); return error_mark_node; } cnt++; @@ -3232,7 +3230,7 @@ get_source_location_impl_type (location_t loc) { if (TREE_CODE (TREE_TYPE (field)) != INTEGER_TYPE) { - error_at (loc, "%qD does not have integral type", field); + error ("%qD does not have integral type", field); return error_mark_node; } cnt++; @@ -3244,9 +3242,9 @@ get_source_location_impl_type (location_t loc) } if (cnt != 4) { - error_at (loc, "% does not contain only " - "non-static data members %<_M_file_name%>, " - "%<_M_function_name%>, %<_M_line%> and %<_M_column%>"); + error ("% does not contain only " + "non-static data members %<_M_file_name%>, " + "%<_M_function_name%>, %<_M_line%> and %<_M_column%>"); return error_mark_node; } return build_qualified_type (type, TYPE_QUAL_CONST); @@ -3337,21 +3335,21 @@ static GTY(()) hash_table *source_location_table; static GTY(()) unsigned int source_location_id; -/* Fold __builtin_source_location () call. LOC is the location - of the call. */ +/* Fold the __builtin_source_location () call T. */ tree -fold_builtin_source_location (location_t loc) +fold_builtin_source_location (const_tree t) { - if (source_location_impl == NULL_TREE) - { - auto_diagnostic_group d; - source_location_impl = get_source_location_impl_type (loc); - if (source_location_impl == error_mark_node) - inform (loc, "evaluating %qs", "__builtin_source_location"); - } + gcc_assert (TREE_CODE (t) == CALL_EXPR); + /* TREE_TYPE (t) is const std::source_location::__impl* */ + tree source_location_impl = TREE_TYPE (TREE_TYPE (t)); if (source_location_impl == error_mark_node) return build_zero_cst (const_ptr_type_node); + gcc_assert (CLASS_TYPE_P (source_location_impl) + && id_equal (DECL_NAME (TYPE_NAME (source_location_impl)), + "__impl")); + + location_t loc = EXPR_LOCATION (t); if (source_location_table == NULL) source_location_table = hash_table ::create_ggc (64); @@ -3427,7 +3425,7 @@ fold_builtin_source_location (location_t loc) entryp->var = var; } - return build_fold_addr_expr_with_type_loc (loc, var, const_ptr_type_node); + return build_fold_addr_expr_with_type_loc (loc, var, TREE_TYPE (t)); } #include "gt-cp-cp-gimplify.h" diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index addd26ea077..8600e6067f9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -235,8 +235,6 @@ enum cp_tree_index CPTI_PSEUDO_CONTRACT_VIOLATION, - CPTI_SOURCE_LOCATION_IMPL, - CPTI_FALLBACK_DFLOAT32_TYPE, CPTI_FALLBACK_DFLOAT64_TYPE, CPTI_FALLBACK_DFLOAT128_TYPE, @@ -395,9 +393,6 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; /* A node which matches any template argument. */ #define any_targ_node cp_global_trees[CPTI_ANY_TARG] -/* std::source_location::__impl class. */ -#define source_location_impl cp_global_trees[CPTI_SOURCE_LOCATION_IMPL] - /* Node to indicate default access. This must be distinct from the access nodes in tree.h. */ @@ -8295,7 +8290,8 @@ extern tree process_stmt_hotness_attribute (tree, location_t); extern tree build_assume_call (location_t, tree); extern tree process_stmt_assume_attribute (tree, tree, location_t); extern bool simple_empty_class_p (tree, tree, tree_code); -extern tree fold_builtin_source_location (location_t); +extern tree fold_builtin_source_location (const_tree); +extern tree get_source_location_impl_type (); /* in name-lookup.cc */ extern tree strip_using_decl (tree); diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 715c739b6e5..07c55ba19b6 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -4669,9 +4669,13 @@ cxx_init_decl_processing (void) BUILT_IN_FRONTEND, NULL, NULL_TREE); set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF); - tree cptr_ftype = build_function_type_list (const_ptr_type_node, NULL_TREE); + /* The concrete return type of __builtin_source_location is + const std::source_location::__impl*, but we can't form the type + at this point. So we initially use a deduced return type and + update it from require_deduced_type upon first use. */ + tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE); decl = add_builtin_function ("__builtin_source_location", - cptr_ftype, CP_BUILT_IN_SOURCE_LOCATION, + auto_ftype, CP_BUILT_IN_SOURCE_LOCATION, BUILT_IN_FRONTEND, NULL, NULL_TREE); set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF); @@ -18751,6 +18755,23 @@ require_deduced_type (tree decl, tsubst_flags_t complain) { if (undeduced_auto_decl (decl)) { + if (TREE_CODE (decl) == FUNCTION_DECL + && fndecl_built_in_p (decl, BUILT_IN_FRONTEND) + && DECL_FE_FUNCTION_CODE (decl) == CP_BUILT_IN_SOURCE_LOCATION) + { + /* Determine the return type of __builtin_source_location. */ + tree type = get_source_location_impl_type (); + if (type == error_mark_node) + { + inform (input_location, "using %qs", "__builtin_source_location"); + return false; + } + type = cp_build_qualified_type (type, TYPE_QUAL_CONST); + type = build_pointer_type (type); + apply_deduced_return_type (decl, type); + return true; + } + if (warning_suppressed_p (decl) && seen_error ()) /* We probably already complained about deduction failure. */; else if (complain & tf_error) diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc10.C b/gcc/testsuite/g++.dg/cpp2a/srcloc10.C index 1be78d9f7bd..aa8cf98880c 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc10.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc10.C @@ -10,4 +10,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'std::source_location::__impl' does not contain only non-static data members '_M_file_name', '_M_function_name', '_M_line' and '_M_column'" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc11.C b/gcc/testsuite/g++.dg/cpp2a/srcloc11.C index abc850fcd43..07281ca0ad0 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc11.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc11.C @@ -10,4 +10,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'std::source_location::__impl' does not contain only non-static data members '_M_file_name', '_M_function_name', '_M_line' and '_M_column'" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc12.C b/gcc/testsuite/g++.dg/cpp2a/srcloc12.C index 49a7e569b7f..445c4a13374 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc12.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc12.C @@ -11,4 +11,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'std::source_location::__impl::_M_file_name' does not have 'const char \\*' type" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc13.C b/gcc/testsuite/g++.dg/cpp2a/srcloc13.C index ee7b1248354..d63f6c7d932 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc13.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc13.C @@ -12,4 +12,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'std::source_location::__impl::_M_line' does not have integral type" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc3.C b/gcc/testsuite/g++.dg/cpp2a/srcloc3.C index 29587e4ebb5..324e03cd548 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc3.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc3.C @@ -2,4 +2,4 @@ auto x = __builtin_source_location (); // { dg-error "'source_location' is not a member of 'std'" } // { dg-message "std::source_location' is defined in header ''; did you forget to '#include '" "" { target *-*-* } .-1 } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-2 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-2 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc4.C b/gcc/testsuite/g++.dg/cpp2a/srcloc4.C index c10f64b95d2..9e92c449fc3 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc4.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc4.C @@ -5,4 +5,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'void std::source_location\\(\\)' is not a type" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc5.C b/gcc/testsuite/g++.dg/cpp2a/srcloc5.C index ce7170b6dce..ed4b9351f74 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc5.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc5.C @@ -6,4 +6,4 @@ namespace std { auto x = __builtin_source_location (); // { dg-error "'std::source_location'\[^\n\r]*is not a class type" } // { dg-error "'__impl' is not a member of 'std::source_location'" "" { target *-*-* } .-1 } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-2 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-2 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc6.C b/gcc/testsuite/g++.dg/cpp2a/srcloc6.C index 89c6887cb46..bec51e290b2 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc6.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc6.C @@ -6,4 +6,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'__impl' is not a member of 'std::source_location'" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc7.C b/gcc/testsuite/g++.dg/cpp2a/srcloc7.C index ef56edf9426..c81fa63f418 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc7.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc7.C @@ -7,4 +7,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'std::source_location::__impl\\(\\)' is not a type" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc8.C b/gcc/testsuite/g++.dg/cpp2a/srcloc8.C index caef812b464..158cc3f93d1 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc8.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc8.C @@ -7,4 +7,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'std::source_location::__impl()' is not a class type" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/srcloc9.C b/gcc/testsuite/g++.dg/cpp2a/srcloc9.C index 47fce003913..618e0935632 100644 --- a/gcc/testsuite/g++.dg/cpp2a/srcloc9.C +++ b/gcc/testsuite/g++.dg/cpp2a/srcloc9.C @@ -8,4 +8,4 @@ namespace std { } auto x = __builtin_source_location (); // { dg-error "'std::source_location::__impl' does not contain only non-static data members '_M_file_name', '_M_function_name', '_M_line' and '_M_column'" } -// { dg-message "evaluating '__builtin_source_location'" "" { target *-*-* } .-1 } +// { dg-message "using '__builtin_source_location'" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/g++.dg/modules/pr100881_a.C b/gcc/testsuite/g++.dg/modules/pr100881_a.C new file mode 100644 index 00000000000..94e9f742798 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr100881_a.C @@ -0,0 +1,28 @@ +// PR c++/100881 +// { dg-additional-options "-std=c++20 -fmodules-ts" } +// { dg-module-cmi pr100881 } +module; +#include +export module pr100881; + +export consteval int +current_line_fn(const std::source_location& loc = std::source_location::current()) +{ + return loc.line(); +} + +export struct current_line_cls +{ + int line = std::source_location::current().line(); +}; + +export template consteval int +current_line_fn_tmpl(const std::source_location& loc = std::source_location::current()) +{ + return loc.line(); +} + +export template struct current_line_cls_tmpl +{ + int line = std::source_location::current().line(); +}; diff --git a/gcc/testsuite/g++.dg/modules/pr100881_b.C b/gcc/testsuite/g++.dg/modules/pr100881_b.C new file mode 100644 index 00000000000..7f25b21b354 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr100881_b.C @@ -0,0 +1,8 @@ +// PR c++/100881 +// { dg-additional-options "-std=c++20 -fmodules-ts" } +import pr100881; + +static_assert(current_line_fn() == 5); +static_assert(current_line_cls{}.line == 6); +static_assert(current_line_fn_tmpl() == 7); +static_assert(current_line_cls_tmpl{}.line == 8);