r0ng r0ng -4 years ago 71
C++ Question

c++ error: error: explicit qualification in declaration in deduction guide c++1z

I was trying an example about 1z's deduction guide by using gcc 8.0.0 201706 (Unable to get the code compiled by using clang 5.0.5).

namespace std
{

template<class R, class CLS, class ... ARGS> std::function(R(CLS::*)(ARGS ...)) -> function< R(CLS &, ARGS...)>;
}


The compiler complains that

error: explicit qualification in declaration of 'std::function(R (CLS::*)(ARGS ...))-> std::function<R(CLS&, ARGS ...)>'
-> function< R(CLS &, ARGS...)>;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~


Based on explicit qualification in C++ declaration the qualification 'std::' should be removed to make the declaration right.

But when I change the deduction guide declaration to (NOTICE the qualification 'std::' is added after '->'). There is no compiler errors:

template<class R, class CLS, class ... ARGS> function(R(CLS::*)(ARGS ...))-> std::function< R(CLS &, ARGS...)>;


I assume the whole express is a declaration, but it seems the part after '->' is not.

It seems to me that a qualification is able to be used on one part of expression but not the other parts is a bit confusing. Is anyone able to explain the reason behind why the last expression is valid?

Thanks

Answer Source

The syntax of a deduction-guide does not allow qualification on either function in your example. The syntax is:

deduction-guide:
    explicit(opt) template-name (parameter-declaration-clause) -> simple-template-id;

A template-name must be an identifier (therefore it cannot be a qualified name) and a simple-template-id refers to a template-name together with its template arguments.

The compiler may still allow redundant qualification as a conforming extension provided that it issues a diagnostic (i.e., a warning). If there is not at least a warning, it is a compiler bug, although I would wait until C++17 is finalized before filing a bug report.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download