Commit c88bf19b authored by Milian Wolff's avatar Milian Wolff

clang: add new (partially failing) test file for lambdas

We apparently fail to build uses for lambda captures using
C++14 `identifier initializer` statements. Turns out that the
init-capture isn't visited by libclang, see also:

https://reviews.llvm.org/D60672
parent d8119c13
/// "useCount" : 1
void foo()
{
/// "useCount": 2
auto l1 = []() {
foo();
};
/// "useCount": 1
auto l2 = [l1] {
l1();
};
/// "useCount": 0
auto l3 = [lambda = l2]() {
lambda();
};
}
......@@ -29,6 +29,7 @@
#include <tests/json/declarationvalidator.h>
#include "testfilepaths.h"
#include "testprovider.h"
//Include all used json tests, otherwise "Test not found"
#include <tests/json/jsondeclarationtests.h>
......@@ -55,13 +56,22 @@ void TestFiles::initTestCase()
DUChain::self()->disablePersistentStorage();
Core::self()->languageController()->backgroundParser()->setDelay(0);
CodeRepresentation::setDiskChangesForbidden(true);
m_provider = new TestEnvironmentProvider;
IDefinesAndIncludesManager::manager()->registerBackgroundProvider(m_provider);
}
void TestFiles::cleanupTestCase()
{
delete m_provider;
TestCore::shutdown();
}
void TestFiles::cleanup()
{
m_provider->clear();
}
void TestFiles::testFiles_data()
{
QTest::addColumn<QString>("fileName");
......@@ -75,6 +85,11 @@ void TestFiles::testFiles_data()
void TestFiles::testFiles()
{
QFETCH(QString, fileName);
if (QTest::currentDataTag() == QLatin1String("lambdas.cpp")) {
m_provider->parserArguments += "-std=c++14";
}
const IndexedString indexedFileName(fileName);
ReferencedTopDUContext top =
DUChain::self()->waitForUpdate(indexedFileName, TopDUContext::AllDeclarationsContextsAndUses);
......@@ -88,12 +103,14 @@ void TestFiles::testFiles()
DUChainReadLocker lock;
DeclarationValidator validator;
top->visit(validator);
QVERIFY(validator.testsPassed());
foreach(auto problem, top->problems()) {
qDebug() << problem;
}
QEXPECT_FAIL("lambdas.cpp", "capture with identifier and initializer aren't visited apparently", Abort);
QVERIFY(validator.testsPassed());
if (!QTest::currentDataTag() || strcmp("invalid.cpp", QTest::currentDataTag()) != 0) {
QVERIFY(top->problems().isEmpty());
}
......
......@@ -22,14 +22,19 @@
#include <QObject>
class TestEnvironmentProvider;
class TestFiles : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void cleanup();
void testFiles_data();
void testFiles();
private:
TestEnvironmentProvider *m_provider;
};
#endif // TEST_FILES_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment