public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114138] New: [c++2b] ICE on valid code using `auto(expr)` DECAY-COPY
@ 2024-02-27 17:59 eric.niebler at gmail dot com
  2024-02-27 19:46 ` [Bug c++/114138] " ppalka at gcc dot gnu.org
  2024-03-01 17:51 ` cvs-commit at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: eric.niebler at gmail dot com @ 2024-02-27 17:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114138

            Bug ID: 114138
           Summary: [c++2b] ICE on valid code using `auto(expr)`
                    DECAY-COPY
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eric.niebler at gmail dot com
  Target Milestone: ---

Compile the following with -c++=2b:


```
namespace std {
  template <class T>
  T&& declval() noexcept requires true;

  template <class>
  void declval() noexcept;

  namespace detail {
    struct none_such;
    template <class>
    using none_such_t = none_such;

    template <class T>
      extern const none_such_t<T> _getter_for;

    template <class T>
    using _decay_t = decltype(auto(declval<T>()));

    static_assert(__is_same_as(_decay_t<void>, void));
  }

  template <const auto& Fn, class... Args>
    using _result_of_t = decltype(Fn(declval<Args>()...));

  template <unsigned I, class Tuple>
    using tuple_element_t =
_result_of_t<detail::_getter_for<detail::_decay_t<Tuple>>, char(*)[I+1],
Tuple>;

  template <class First, class Second>
  struct pair {
    First first;
    Second second;
  };

  template <class>
    inline constexpr bool _is_pair = false;

  template <class First, class Second>
    inline constexpr bool _is_pair<pair<First, Second>> = true;

  template <class T>
    concept Pair = _is_pair<decltype(auto(std::declval<T>()))>;

  template <unsigned I, Pair P>
    requires (I <= 1)
  decltype(auto) get(P&& p) noexcept {
    if constexpr (I == 0) {
      return (static_cast<P&&>(p).first);
    } else {
      return (static_cast<P&&>(p).second);
    }
  }

  namespace detail {
    inline constexpr auto _pair_getter =
      []<unsigned J, class Pair>(char(*)[J], Pair&& p) noexcept ->
decltype(auto) {
        return std::get<J-1>(static_cast<Pair&&>(p));
      };

    template <class First, class Second>
      inline constexpr auto _getter_for<pair<First, Second>> = _pair_getter;
  }

}

int main() {

  static_assert(__is_same_as(int&, std::tuple_element_t<0, std::pair<int,
float>&>));
  static_assert(__is_same_as(float&&, std::tuple_element_t<1, std::pair<int,
float>&&>));
}
```


Result:

```
<source>: In substitution of 'template<unsigned int I, class Tuple> using
std::tuple_element_t = std::_result_of_t<_getter_for<decltype
((auto)(declval<Tuple>()))>, char (*)[(I + 1)], Tuple> [with unsigned int I =
0; Tuple = std::pair<int, float>&]':
<source>:71:82:   required from here
   71 |   static_assert(__is_same_as(int&, std::tuple_element_t<0,
std::pair<int, float>&>));
      |                                                                        
         ^
<source>:21:31: internal compiler error: in tsubst, at cp/pt.cc:16367
   21 |     using _decay_t = decltype(auto(declval<T>()));
      |                               ^~~~~~~~~~~~~~~~~~
0x265412c internal_error(char const*, ...)
        ???:0
0xa548c3 fancy_abort(char const*, int, char const*)
        ???:0
0xc99307 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc9f3c9 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc9f3c9 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc98a19 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc80873 instantiate_template(tree_node*, tree_node*, int)
        ???:0
0xc9a0fc tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xc973cc lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
        ???:0
0xcd370f finish_template_type(tree_node*, tree_node*, int)
        ???:0
0xc577da c_parse_file()
        ???:0
0xdaba19 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```

See https://godbolt.org/z/r13Yff5bM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/114138] [c++2b] ICE on valid code using `auto(expr)` DECAY-COPY
  2024-02-27 17:59 [Bug c++/114138] New: [c++2b] ICE on valid code using `auto(expr)` DECAY-COPY eric.niebler at gmail dot com
@ 2024-02-27 19:46 ` ppalka at gcc dot gnu.org
  2024-03-01 17:51 ` cvs-commit at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-02-27 19:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114138

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2024-02-27
           Keywords|                            |rejects-valid
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/114138] [c++2b] ICE on valid code using `auto(expr)` DECAY-COPY
  2024-02-27 17:59 [Bug c++/114138] New: [c++2b] ICE on valid code using `auto(expr)` DECAY-COPY eric.niebler at gmail dot com
  2024-02-27 19:46 ` [Bug c++/114138] " ppalka at gcc dot gnu.org
@ 2024-03-01 17:51 ` cvs-commit at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-01 17:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114138

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:a6a1920b592b58c38137c5c891b3bbb02b084f38

commit r14-9260-ga6a1920b592b58c38137c5c891b3bbb02b084f38
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Mar 1 12:50:18 2024 -0500

    c++: auto(x) partial substitution [PR110025, PR114138]

    In r12-6773-g09845ad7569bac we gave CTAD placeholders a level of 0 and
    ensured we never replaced them via tsubst.  It turns out that autos
    representing an explicit cast need the same treatment and for the same
    reason: such autos appear in an expression context and so their level
    gets easily messed up after partial substitution, leading to premature
    replacement via an incidental tsubst instead of via do_auto_deduction.

    This patch fixes this by extending the r12-6773 approach to auto(x).

            PR c++/110025
            PR c++/114138

    gcc/cp/ChangeLog:

            * cp-tree.h (make_cast_auto): Declare.
            * parser.cc (cp_parser_functional_cast): If the type is an auto,
            replace it with a level-less one via make_cast_auto.
            * pt.cc (find_parameter_packs_r): Don't treat level-less auto
            as a type parameter pack.
            (tsubst) <case TEMPLATE_TYPE_PARM>: Generalize CTAD placeholder
            auto handling to all level-less autos.
            (make_cast_auto): Define.
            (do_auto_deduction): Handle replacement of a level-less auto.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp23/auto-fncast16.C: New test.
            * g++.dg/cpp23/auto-fncast17.C: New test.
            * g++.dg/cpp23/auto-fncast18.C: New test.

    Reviewed-by: Jason Merrill <jason@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-01 17:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 17:59 [Bug c++/114138] New: [c++2b] ICE on valid code using `auto(expr)` DECAY-COPY eric.niebler at gmail dot com
2024-02-27 19:46 ` [Bug c++/114138] " ppalka at gcc dot gnu.org
2024-03-01 17:51 ` cvs-commit at gcc dot gnu.org

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).