Why can't we correctly parse a qualified type name in an explicit call to the destructor?

Consider an example.

#include <string>

struct S {
    S() {
        new (&s) std::string("hi");
    }

    ~S() {
        // does not compile
        // s.~std::string();

        // compiles
        using std::string;
        s.~string();
    }

    union {
        std::string s;
    };
};

Why is the comment part not compiling?

The error message that I get from clang shows that the compiler itself parses stdas a type.

identifier 'std' in object destruction expression does not name type

Why can't the compiler determine what std::stringa type is? Is this ambiguous in some way?

I became aware of this from a presentation by Andrei Alexandrescu. It's at 37:10. He quickly comments that it will not “analyze” if the type name is qualified, but does not explain why.

http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C

( "parse" , , . . , - .)

+4
1

, std::string . , , ~string() .

std::string <string>, , typedef ( ) std::basic_string<char>.

A typedef typedef some_class_name another_name ~another_name.

0

Source: https://habr.com/ru/post/1569726/


All Articles