From 882dd60aad7e7718f9cc067baab3ca725f061e10 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 3 Nov 2020 14:25:46 +0100 Subject: [PATCH] C++: Extend alias declaration support in built-in parser The type-id in an alias declaration can also define a new type. Change-Id: I65dc397d2526c56334676c6ab522564f6748d594 Task-number: QTCREATORBUG-24875 Reviewed-by: Christian Stenger --- src/libs/3rdparty/cplusplus/Parser.cpp | 19 ++++++++++++++++--- .../auto/cplusplus/cxx11/data/aliasDecl.1.cpp | 2 ++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp index 3c509be00c0..1550c8b31d8 100644 --- a/src/libs/3rdparty/cplusplus/Parser.cpp +++ b/src/libs/3rdparty/cplusplus/Parser.cpp @@ -1527,10 +1527,23 @@ bool Parser::parseDeclSpecifierSeq(SpecifierListAST *&decl_specifier_seq, } else if (! onlySimpleTypeSpecifiers && ! has_type_specifier && (LA() == T_TYPENAME || LA() == T_ENUM || lookAtClassKey())) { // typename-specifier, elaborated-type-specifier - int startOfElaboratedTypeSpecifier = cursor(); + int startOfTypeSpecifier = cursor(); if (! parseElaboratedTypeSpecifier(*decl_specifier_seq_ptr)) { - error(startOfElaboratedTypeSpecifier, "expected an elaborated type specifier"); - break; + rewind(startOfTypeSpecifier); + if (LA() == T_ENUM) { + if (!parseEnumSpecifier(*decl_specifier_seq_ptr)) { + error(startOfTypeSpecifier, "expected an enum specifier"); + break; + } + } else if (lookAtClassKey()) { + if (!parseClassSpecifier(*decl_specifier_seq_ptr)) { + error(startOfTypeSpecifier, "expected a class specifier"); + break; + } + } else { + error(startOfTypeSpecifier, "expected an elaborated type specifier"); + break; + } } decl_specifier_seq_ptr = &(*decl_specifier_seq_ptr)->next; has_type_specifier = true; diff --git a/tests/auto/cplusplus/cxx11/data/aliasDecl.1.cpp b/tests/auto/cplusplus/cxx11/data/aliasDecl.1.cpp index 99384acaa17..50c6312a790 100644 --- a/tests/auto/cplusplus/cxx11/data/aliasDecl.1.cpp +++ b/tests/auto/cplusplus/cxx11/data/aliasDecl.1.cpp @@ -2,3 +2,5 @@ using Foo = int; using Bar = std::vector::value_type; using A [[foo]] = const float; using B alignas(void*) = C *; +using C = struct {}; +using D = enum class E {A, B};