public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97852] New: Parameter pack not found
@ 2020-11-16 15:25 lf-bt at thax dot hardliners.org
  2020-11-19 18:33 ` [Bug c++/97852] " mpolacek at gcc dot gnu.org
  2021-08-17  8:13 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: lf-bt at thax dot hardliners.org @ 2020-11-16 15:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97852
           Summary: Parameter pack not found
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lf-bt at thax dot hardliners.org
  Target Milestone: ---

The following C++ code compiles fine with clang and msvc without changes, but 
g++ generates 
  error: expected parameter pack before '...'
which does not help at all. The problem is also reproducible with gcc-8 and in
c++11 mode (with some alterations, e.g. non-std index_sequence impl), which
does would allow auto return type deduction used in the second workaround.
(also https://godbolt.org/z/3qPjvn ):

#include <utility>

template <typename T, T... Vals>
struct table256 {
  static constexpr const T data[256] = { Vals... };
};
template <typename T, T... Vals> constexpr const T table256<T,
Vals...>::data[256];

template <typename Str>
constexpr int find_value(Str str, char val)
{
  for (int i = 0; i < (int)str.size; i++) {
    if (str.data[i] == val) {
      return i;
    }
  }
  return -1;
}

template <typename Str, std::size_t... Is>
constexpr auto make_lookup_table256_impl(Str str, std::index_sequence<Is...>)
  -> table256<decltype(find_value(str, 0)), find_value(str, Is)...>
//  -> table256<decltype(find_value(str, 0)), find_value(Str{}, Is)...>  //
workaround 1
{
//  return table256<decltype(find_value(str, 0)), find_value(str, Is)...>{}; 
// workaround 2
  return {};
}

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

* [Bug c++/97852] Parameter pack not found
  2020-11-16 15:25 [Bug c++/97852] New: Parameter pack not found lf-bt at thax dot hardliners.org
@ 2020-11-19 18:33 ` mpolacek at gcc dot gnu.org
  2021-08-17  8:13 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-11-19 18:33 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Reduced.  Not sure if valid.

template <typename T, T> struct S;
template <typename T, long... N> auto foo(T t) -> S<decltype(0), (t, N)...>;

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

* [Bug c++/97852] Parameter pack not found
  2020-11-16 15:25 [Bug c++/97852] New: Parameter pack not found lf-bt at thax dot hardliners.org
  2020-11-19 18:33 ` [Bug c++/97852] " mpolacek at gcc dot gnu.org
@ 2021-08-17  8:13 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-17  8:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I don't think this is valid, t cannot show up in a constexpr.
ICC rejects this with a decent error message too:
<source>(3): error: a parameter is not allowed

And if we use foo MSVC rejects it:
<source>(7): error C2672: 'foo': no matching overloaded function found
<source>(7): error C2770: invalid explicit template argument(s) for
'S<int,t,N...> foo(T)'
<source>(3): note: see declaration of 'foo'


That is:
template <typename T, T...> struct S {};

template <typename T, long... N>  auto foo(T t) -> S<decltype(0), (t, N)...>;

auto g(void)
{
    return foo<int, 1>(100);
}

Note I don't think the original is valid either.

Take this C++17 code:
template <typename T, T...> struct S {};

constexpr int f(int, long) { return 0;}

template <typename T, long... N> constexpr auto foo(int t)
{
    S<decltype(0), f(t, N)...> t1;
    return t1;
}

auto g(void)
{
    return foo<int, 1>(100);
}
---- CUT ----
All compilers reject this above code as invalid.
GCC with:
<source>: In instantiation of 'constexpr auto foo(int) [with T = int; long int
...N = {1}]':
<source>:13:23:   required from here
<source>:7:32: error: 't' is not a constant expression
    7 |     S<decltype(0), f(t, N)...> t1;
      |                                ^~
<source>:7:21: note: in template argument for type 'int'
    7 |     S<decltype(0), f(t, N)...> t1;
      |                    ~^~~~~~
<source>:7:32: error: 't' is not a constant expression
    7 |     S<decltype(0), f(t, N)...> t1;
      |                                ^~
<source>:7:21: note: in template argument for type 'int'
    7 |     S<decltype(0), f(t, N)...> t1;
      |                    ~^~~~~~

Clang with 
<source>:7:20: error: non-type template argument is not a constant expression
    S<decltype(0), f(t, N)...> t1;
                   ^~~~~~~
<source>:13:12: note: in instantiation of function template specialization
'foo<int, 1L>' requested here
    return foo<int, 1>(100);
           ^
<source>:7:22: note: function parameter 't' with unknown value cannot be used
in a constant expression
    S<decltype(0), f(t, N)...> t1;
                     ^
<source>:5:57: note: declared here
template <typename T, long... N> constexpr auto foo(int t)
                                                        ^


this is similar to workaround 2 but with an instantiation to show that
workaround 2 does not work really.

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

end of thread, other threads:[~2021-08-17  8:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16 15:25 [Bug c++/97852] New: Parameter pack not found lf-bt at thax dot hardliners.org
2020-11-19 18:33 ` [Bug c++/97852] " mpolacek at gcc dot gnu.org
2021-08-17  8:13 ` pinskia 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).