71 questions
6
votes
1
answer
146
views
Dependent names in C++ deduction guides and trailing return types - bug in GCC or ill-formed?
A question to C++ standard lawyers. My feeling is that the following code should be 100% accepted, but GCC (all versions supporting C++23 including trunk) rejects constructs using trailing return type ...
7
votes
1
answer
165
views
Effects of dependent names on pack expansions as arguments for non-pack parameters of alias templates
This code produces a compiler error in GCC, Clang, and MSVC (this is a heavily reduced test case for some real code that actually does something useful):
#include <cstdint>
#include <concepts&...
2
votes
0
answers
100
views
Why is a dependent expression not diagnosed as an error in a false if-constexpr block even if it is always a semantic error
There seems to be a lot of confusion out there about if constexpr and the difference between dependent- and non-dependent expressions, particularly in the context of static_assert. Before CWG2518, ...
1
vote
0
answers
77
views
How is lookup of a type different when used for member declaration vs declaration of a local variable in a template?
Consider this example to illustrate that a nested type needs to be looked up via a dependent name, otherwise there'll be errors:
template <typename T>
struct base {
struct inner{};
};
...
3
votes
1
answer
156
views
Using-declaration to introduce dependent name from base class template
To use a name from dependent base class in derived class template (e.g. B<T>), one has to add a prefix highlighting to the compiler that is a dependent name (B<T>::). And to avoid doing it ...
1
vote
1
answer
80
views
Why do a SFINAE function template and a regular function template have different binding rules?
I had a checker function that used the requires keyword to detect if a target function was defined or not. I wanted to make it work with C++17, so I switched the checker from using requires to using ...
10
votes
1
answer
3k
views
Use of template keyword before dependent template name
Considering the following code example, I would expect to have to use the template keyword here to guide the compiler to treat variable v as a template. However, MSVC rejects the use of the template ...
3
votes
1
answer
756
views
error: type/value mismatch in template parameter list for std::variant
The following code doesn't work if class some_class is templated. So my guess is that I have to put the template specifier in front of something, but I don't really know where? I tried putting it in ...
3
votes
0
answers
170
views
Template name disambiguation: g++ vs clang++
Premise: g++ and clang++ are known to be sometime discordant or not compliant on applying the rules for template disambiguation for dependent names.
In this regard, the following code compiles under g+...
5
votes
1
answer
3k
views
std::basic_string<T>::size_type causes compile error in C++20 mode [duplicate]
Here is a simple code that MSVC 2022 compiles in C++17 mode, but fails in C++20 mode:
template <typename T>
void foo()
{
std::basic_string<T>::size_type bar_size; //This fails to ...
0
votes
1
answer
206
views
Is there an equivalent of "typename" for template types? [duplicate]
We have a template member function of the form:
template <template <class> class TT>
TT<some_type> foo() const;
Now, in an invocation context where TT is explicitly specified from a ...
2
votes
1
answer
67
views
Lookup of dependent qualified names
This program does not compile (error: 'foo' is not a member of 'N'):
namespace N {
// void foo();
}
template<class T>
void template_func(T t) {
N::foo(t);
}
But if we uncomment the ...
0
votes
2
answers
171
views
Why in a template we can use a dependent name without being already declared if not instantiated?
I have written this code to understand template name lookup:
//void bar(int);
template <typename T>
void foo(T x)
{
bar(x);
}
void bar(int x)
{
std::cout << "bar(int)\n"...
4
votes
1
answer
89
views
Is a diagnostic required for incorrect uses of non-dependent names in a template that is never instantiated?
Here's what the standard says about non-dependent names in a template definition:
Non-dependent names used in a template definition are found using the usual name lookup and bound at the point they ...
1
vote
0
answers
46
views
C++ primer 5th ed templates dependent and non-dependent names
In C++ Primer 5th edition Chapter16 on templates:
"It is up to the provider of a template to ensure that all names that do not depend on a template parameter are visible when the template is used....