Reputation: 2271
I was compiling the following code and GCC seems to accept the following code.
#include <map>
template<typename K, typename V>
class my_map {
private:
std::map<K, V> mmap;
public:
typedef std::map<K, V>::iterator iterator;
typedef std::map<K, V>::const_iterator const_iterator;
iterator begin() {return mmap.begin();}
const_iterator begin() const {return mmap.begin();}
};
int main()
{
my_map<int, int>::iterator whatever;
return 0;
}
But clang complains about the missing typename
keyword.
The complaint of clang makes more sense to me. Is this a GCC bug?
Edit: Obviously, Where and why do I have to put the "template" and "typename" keywords? does not answer my question, as I am not asking what typename
keyword is, but asking about different behaviors of compilers.
Edit: Now the program is accepted by both clang(from version 16) and gcc.
Upvotes: 2
Views: 351
Reputation: 1
asking about different behaviors of compilers.
It seems that Clang has not implemented this C++20 feature yet. This can be seen from compiler support documentation. This means clang is not standard compliant.
C++20 feature | Paper(s) | GCC | Clang | MSVC | Apple Clang |
---|---|---|---|---|---|
Allow lambda-capture [=, this] | P0409R2 | 8 | 6 | 19.22* | 10.0.0* |
Make typename more optional |
P0634R3 | 9 | 19.29 (16.10)* | ||
Pack expansion in lambda init-capture | P0780R2 | 9 | 9 | 19.22* | 11.0.3* |
As we can see in the above above table, the entry for clang corresponding to "Make typename more optional" is blank.
On the other hand GCC and MSVC have implemented this C++20 feature and so are standard compliant. GCC and MSVC Demo
As of 03/11/2022, clang supports this with version 16 as shown in the updated table below:
C++20 feature | Paper(s) | GCC | Clang | MSVC | Apple Clang |
---|---|---|---|---|---|
Allow lambda-capture [=, this] | P0409R2 | 8 | 6 | 19.22* | 10.0.0* |
Make typename more optional |
P0634R3 | 9 | 16 | 19.29 (16.10)* | |
Pack expansion in lambda init-capture | P0780R2 | 9 | 9 | 19.22* | 11.0.3* |
The program compiles with clang trunk.
Upvotes: 2