Consider a example in the standard
Example
template<class T> struct A {
typedef int M;
struct B {
typedef void M;
struct C;
};
};
template<class T> struct A<T>::B::C : A<T> {
M m; // OK, A<T>::M
};
The comment says M
refer to A<T>::M
, I doubt with this, because of these rules:
temp.dep#3
In the definition of a class or class template, the scope of a dependent base class is not examined during unqualified name lookup either at the point of definition of the class template or member or during an instantiation of the class template or member.
That means a name in the scope of dependent base class is never be considered during unqualified name lookup.
Name M
is an unqualified name. Hence M
declared in A<T>
is not considered.
Then according to the rule for unqualified name lookup, that is:
basic.lookup.unqual#8
For the members of a class X, a name used in a member function body, in a default argument, in a noexcept-specifier, in the brace-or-equal-initializer of a non-static data member, or in the definition of a class member outside of the definition of X, following the member's declarator-id32, shall be declared in one of the following ways:
- if X is a nested class of class Y, shall be a member of Y, or shall be a member of a base class of Y (this lookup applies in turn to Y's enclosing classes, starting with the innermost enclosing class)
Since C
is a nested class of B
, Hence I think lookup shall be began at B
, then A
, due to there's a name M
in the scope of B
, hence the lookup shall be stoped.
In all the cases listed in [basic.lookup.unqual], the scopes are searched for a declaration in the order listed in each of the respective categories; name lookup ends as soon as a declaration is found for the name. If no declaration is found, the program is ill-formed.
So, according to these rules, the name M
within A<T>::B::C
shall refer to B::M
.
The outcome is here.
GCC agreed what the standard said, however clang
reported an error and denoted that the type M
is void
. The outcome of clang
consistent with my analysis. According to these reasons, I agree clang
is right.
So, I wonder is it a defect? Or what something I misunderstand ?
A dependent name is a name that depends on the type or the value of a template parameter. For example: template<class T> class U : A<T> { typename T::B x; void f(A<T>& y) { *y++; } }; The dependent names in this example are the base class A<T> , the type name T::B , and the variable y .
A dependent name is essentially a name that depends on a template parameter. A dependent name can be a type, a non-type, or a template parameter. To express that a dependent name stands for a type or a template, you have to use the keywords typename or template .
Technically (and truly), C++ has dependent types, as types can depend on values ... | Hacker News.
2. Which value is placed in the base class? Explanation: We can place the default type values in a base class and overriding some of them through derivation.
Here we’ll help you get started by explaining the most common ways to classify defects in different products. Quality control professionals typically classify quality defects into three main categories: minor, major and critical. The nature and severity of a defect determines in which of the three categories it belongs.
This existing class is called the base class, and the new class is referred to as the derived class. A class can be derived from more than one class or interface, which means that it can inherit data and functions from multiple base classes or interfaces. The following is the syntax of base class in C# −
It include the defects made by the developer in some arithmetic expression or mistake in finding solution of such arithmetic expression. This type of defects are basically made by the programmer due to access work or less knowledge. Code congestion may also lead to the arithmetic defects as programmer is unable to properly watch the written code.
When a developer or programmer during the development phase makes some mistake then that turns into bugs that are called defects. It is basically caused by the developers’ mistakes.
According to C++ Defect Report Support in Clang, currently (2020-07-06) Clang does not implement the resolution of CWG591, where the paragraph with the definition of dependent base class and the Example you cite in the question was added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With