[cfe-dev] c++14 vs c++17 different ast for lambda?

Evgeniy Dushistov via cfe-dev cfe-dev at lists.llvm.org
Tue May 4 18:52:54 PDT 2021


Hi,

I am trying to investigate bug in the tool based on
libclang. The problem is that with -std=c++14 and -std=c++17
for code like this:

#define signals public
class QObject {
signals:
        void destroyed();
public:
        template<typename F>
        static void connect(QObject *, void (QObject::*mf)(void), F f) {}
        void deleteLater();
};

void test(QObject *o1, QObject *o2)
{
    QObject::connect(o1, &QObject::destroyed,
                    [=] { o2->deleteLater(); });
}

clang dumps different AST. Is this intentional because of
difference in handling of lambdas in c++14 and c++17 or this is
some kind of bug?

In case of -std=c++14 (clang++ -std=c++14 -Xclang -ast-dump -c test.cpp)
3rd argument (lambda) passed to QObject::connect looks like this:
CXXConstructExpr 0x5589e3278970 <line:14:21, col:46> '(lambda at test.cpp:14:21)':'(lambda at test.cpp:14:21)' 'void ((lambda at test.cpp:14:21) &&) noexcept' elidable
          `-MaterializeTemporaryExpr 0x5589e3275cd0 <col:21, col:46> '(lambda at test.cpp:14:21)' xvalue
            `-LambdaExpr

in case of -std=c++17 lambda looks like this:
   `-LambdaExpr 0x5641f55db880 <line:14:21, col:46> '(lambda at test.cpp:14:21)'
        |-CXXRecordDecl 0x5641f55db420 <col:21> col:21 implicit class definition

-- 
/Evgeniy


More information about the cfe-dev mailing list