public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99672] std::source_location yield different column numbers between free function and template functions Date: Fri, 19 Mar 2021 16:36:49 +0000 [thread overview] Message-ID: <bug-99672-4-MaqVhxfNde@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-99672-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99672 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Adjusted testcase without headers. namespace std { struct source_location { struct __impl { const char *_M_file_name; const char *_M_function_name; unsigned int _M_line, _M_column; }; const __impl *__ptr; constexpr source_location () : __ptr (nullptr) {} static consteval source_location current (const void *__p = __builtin_source_location ()) { source_location __ret; __ret.__ptr = static_cast <const __impl *> (__p); return __ret; } constexpr const char *file_name () const { return __ptr ? __ptr->_M_file_name : ""; } constexpr const char *function_name () const { return __ptr ? __ptr->_M_function_name : ""; } constexpr unsigned line () const { return __ptr ? __ptr->_M_line : 0; } constexpr unsigned column () const { return __ptr ? __ptr->_M_column : 0; } }; } int g(auto...) { return std::source_location::current().column(); } int f() { return std::source_location::current().column(); } int a = g(); int b = f(); I think the standard doesn't specify anything about what exactly the column should be, so using different columns isn't standard violation. In one case we have more detailed locus with ranges: pr99672.C:32:37 start: pr99672.C:32:8 finish: pr99672.C:32:38 i.e. caret on column 37 (the opening paren), start at column 8, end at column 38 (the closing paren), in the other case just a simple location of the closing paren. The thing is that the location for the default argument is set from input_location by break_out_target_exprs called from convert_default_arg. When in template, this is called from tsubst* which sets input_location temporarily from the CALL_EXPR locus and is the detailed one, which was created by cp_parser_postfix_expression: 7728 if (close_paren_loc != UNKNOWN_LOCATION) 7729 { 7730 location_t combined_loc = make_location (token->location, 7731 start_loc, 7732 close_paren_loc); 7733 postfix_expression.set_location (combined_loc); 7734 }
next prev parent reply other threads:[~2021-03-19 16:36 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-19 15:25 [Bug c++/99672] New: " hewillk at gmail dot com 2021-03-19 16:36 ` jakub at gcc dot gnu.org [this message] 2021-03-19 16:55 ` [Bug c++/99672] " jakub at gcc dot gnu.org 2021-03-21 9:18 ` hewillk at gmail dot com 2021-03-25 20:36 ` cvs-commit at gcc dot gnu.org 2021-03-25 20:38 ` jakub at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99672-4-MaqVhxfNde@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).