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                  }

Reply via email to