From 1278baf052dae8b717efdd139709601e098f66ed Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Wed, 30 Jun 2021 19:43:53 -0400 Subject: [PATCH] Bug 464624 - C++ Parser fails with Syntax error on function declaration with __declspec and non-native type Allow __declspec after identifier in decl-specifier. See https://docs.microsoft.com/en-us/cpp/cpp/declspec Change-Id: Ifdaeb649abcfa1b7391e2799072b1afbc07a16a1 Signed-off-by: Marc-Andre Laperle --- .../eclipse/cdt/core/parser/tests/ast2/AST2Tests.java | 11 +++++++++++ .../internal/core/dom/parser/c/GNUCSourceParser.java | 4 ++-- .../core/dom/parser/cpp/GNUCPPSourceParser.java | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 0de181061c8..43056df404f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -5433,6 +5433,17 @@ public class AST2Tests extends AST2TestBase { parseAndCheckBindings(getAboveComment(), CPP, true); } + //typedef struct _MyStruct { + //} MyStruct; + // + //MyStruct __declspec(dllexport) foo; + //MyStruct __declspec(dllexport) __declspec(deprecated) bar; + public void testDeclspecAfterDeclSpecifierIdentifier_464624() throws Exception { + for (ParserLanguage lang : ParserLanguage.values()) { + parseAndCheckBindings(getAboveComment(), lang, true); + } + } + // struct Outer { // struct {int a1;}; // struct {int a2;} a3; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 77e2f6da450..bd63a89dfab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -1162,8 +1162,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(LA(1)); attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(true, false)); break; - case IGCCToken.t__declspec: // __declspec precedes the identifier - if (identifier != null || !supportDeclspecSpecifiers) + case IGCCToken.t__declspec: + if (!supportDeclspecSpecifiers) throwBacktrack(LA(1)); __attribute_decl_seq(false, true); break; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 5ad81884351..4709d51a4e7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -3579,8 +3579,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(LA(1)); attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(true, false)); break; - case IGCCToken.t__declspec: // __declspec precedes the identifier - if (identifier != null || !supportDeclspecSpecifiers) + case IGCCToken.t__declspec: + if (!supportDeclspecSpecifiers) throwBacktrack(LA(1)); attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(false, true)); break;