public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97134] New: partial specialization not more specialized when using CNTTP
@ 2020-09-21  5:52 Darrell.Wright at gmail dot com
  2020-09-23 13:01 ` [Bug c++/97134] " ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Darrell.Wright at gmail dot com @ 2020-09-21  5:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97134
           Summary: partial specialization not more specialized when using
                    CNTTP
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Darrell.Wright at gmail dot com
  Target Milestone: ---

g++, tried trunk on CE along with 10.2 and 10.1 will say the following code is
not more specialized when JSONNAMETYPE is a CNTTP(json_name).  When it's a
NTTP(char const *) it is ok with it.  The code works in MSVC's C++20 mode.
https://godbolt.org/z/7v4nx5

#include <cstddef>
#include <iostream>
#include <string_view>
#include <utility>

template <std::size_t N>
struct json_name {
  static_assert(N > 0);
  char const m_data[N]{};

 private:
  template <std::size_t... Is>
  constexpr json_name(char const (&ptr)[N], std::index_sequence<Is...>)
      : m_data{ptr[Is]...} {}

 public:
  constexpr json_name(char const (&ptr)[N])
      : json_name(ptr, std::make_index_sequence<N>{}) {}

  // Needed for copy_to_iterator
  [[nodiscard]] constexpr char const *begin() const { return m_data; }

  // Needed for copy_to_iterator
  [[nodiscard]] constexpr char const *end() const {
    return m_data + static_cast<ptrdiff_t>(size());
  }

  [[nodiscard]] static constexpr std::size_t size() noexcept { return N - 1; }

  template <std::size_t M>
  constexpr bool operator==(json_name<M> const &rhs) const {
    if (N != M) {
      return false;
    }
    for (std::size_t n = 0; n < N; ++n) {
      if (m_data[n] != rhs.m_data[n]) {
        return false;
      }
    }
    return true;
  }

  constexpr operator std::string_view() const {
    return std::string_view(m_data, size());
  }
};
template <typename... Chars>
json_name(Chars...) -> json_name<sizeof...(Chars)>;

template <std::size_t N>
json_name(char const (&)[N]) -> json_name<N>;

#ifdef USE_CNTTP
#define JSONNAMETYPE json_name
#else
#define JSONNAMETYPE char const *
#endif

template <JSONNAMETYPE Name, typename U>
struct X : std::false_type {
  static constexpr std::string_view name = Name;
};

template <JSONNAMETYPE Name>
struct X<Name, bool> : std::true_type {
  static constexpr std::string_view name = Name;
};

int main() {
  static constexpr char const A[] = "A";  
  static constexpr char const B[] = "B";  
  auto a = X<A, int>::name;
  auto b = X<B, bool>::name;
  std::cout << a << b << '\n';
}

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

* [Bug c++/97134] partial specialization not more specialized when using CNTTP
  2020-09-21  5:52 [Bug c++/97134] New: partial specialization not more specialized when using CNTTP Darrell.Wright at gmail dot com
@ 2020-09-23 13:01 ` ppalka at gcc dot gnu.org
  2021-03-20 14:57 ` omer.rosler at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-09-23 13:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
                 CC|                            |ppalka at gcc dot gnu.org
   Last reconfirmed|                            |2020-09-23

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/97134] partial specialization not more specialized when using CNTTP
  2020-09-21  5:52 [Bug c++/97134] New: partial specialization not more specialized when using CNTTP Darrell.Wright at gmail dot com
  2020-09-23 13:01 ` [Bug c++/97134] " ppalka at gcc dot gnu.org
@ 2021-03-20 14:57 ` omer.rosler at gmail dot com
  2021-04-09 21:20 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: omer.rosler at gmail dot com @ 2021-03-20 14:57 UTC (permalink / raw)
  To: gcc-bugs

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

Omer Rosler <omer.rosler at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |omer.rosler at gmail dot com

--- Comment #2 from Omer Rosler <omer.rosler at gmail dot com> ---
I encountered a similar problem, I think it's the same bug, so I won't open
another ticket.

Much simpler code fails to compile:

```c++
template<typename T>
struct templ {};

template<templ... Vs>
struct wrapper {};

template<templ V, templ... Vs>
struct wrapper<V, Vs...> {};
```

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

* [Bug c++/97134] partial specialization not more specialized when using CNTTP
  2020-09-21  5:52 [Bug c++/97134] New: partial specialization not more specialized when using CNTTP Darrell.Wright at gmail dot com
  2020-09-23 13:01 ` [Bug c++/97134] " ppalka at gcc dot gnu.org
  2021-03-20 14:57 ` omer.rosler at gmail dot com
@ 2021-04-09 21:20 ` ppalka at gcc dot gnu.org
  2021-04-13  3:23 ` cvs-commit at gcc dot gnu.org
  2021-04-13  3:23 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-09 21:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/97134] partial specialization not more specialized when using CNTTP
  2020-09-21  5:52 [Bug c++/97134] New: partial specialization not more specialized when using CNTTP Darrell.Wright at gmail dot com
                   ` (2 preceding siblings ...)
  2021-04-09 21:20 ` ppalka at gcc dot gnu.org
@ 2021-04-13  3:23 ` cvs-commit at gcc dot gnu.org
  2021-04-13  3:23 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-13  3:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS 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:c755e1b3eadaf1c7e751a2c7ce1d418c6db8463a

commit r11-8145-gc755e1b3eadaf1c7e751a2c7ce1d418c6db8463a
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Apr 12 23:22:03 2021 -0400

    c++: variadic class template placeholder deduction [PR97134]

    do_class_deduction handles specially the case where we're deducing one
    placeholder from another equivalent one, but here the initializer passed
    to do_class_deduction is wrapped in an EXPR_PACK_EXPANSION (we're being
    called from unify during get_partial_spec_bindings).  This patch makes
    do_class_deduction look through EXPR_PACK_EXPANSIONs so that we detect
    this case as well.

    gcc/cp/ChangeLog:

            PR c++/97134
            * pt.c (do_class_deduction): Look through EXPR_PACK_EXPANSION
            when checking if the initializer is an equivalent class
            placeholder template parameter.

    gcc/testsuite/ChangeLog:

            PR c++/97134
            * g++.dg/cpp2a/nontype-class43.C: New test.

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

* [Bug c++/97134] partial specialization not more specialized when using CNTTP
  2020-09-21  5:52 [Bug c++/97134] New: partial specialization not more specialized when using CNTTP Darrell.Wright at gmail dot com
                   ` (3 preceding siblings ...)
  2021-04-13  3:23 ` cvs-commit at gcc dot gnu.org
@ 2021-04-13  3:23 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-13  3:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |11.0

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11, thanks for the bug reports.

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

end of thread, other threads:[~2021-04-13  3:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21  5:52 [Bug c++/97134] New: partial specialization not more specialized when using CNTTP Darrell.Wright at gmail dot com
2020-09-23 13:01 ` [Bug c++/97134] " ppalka at gcc dot gnu.org
2021-03-20 14:57 ` omer.rosler at gmail dot com
2021-04-09 21:20 ` ppalka at gcc dot gnu.org
2021-04-13  3:23 ` cvs-commit at gcc dot gnu.org
2021-04-13  3:23 ` ppalka 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).