Skip to content

Commit e6a5f9e

Browse files
authored
Merge pull request #2321 from guwirth/fix-2317
Parsing error when using template type parameter with assignment
2 parents 85522b0 + 246beca commit e6a5f9e

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jdk:
77
- openjdk11
88
env:
99
- SONARLABEL=sonarqube-7.9.6 SONARAPI=SqApi79
10-
- SONARLABEL=sonarqube-8.9.2.46101 SONARAPI=SqApi79
10+
- SONARLABEL=sonarqube-8.9.7.52159 SONARAPI=SqApi79
1111

1212
addons:
1313
# shorten the VM hostname with the new workaround

appveyor.yml

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,28 @@ cache:
2424
install:
2525
- ps: |
2626
Add-Type -AssemblyName System.IO.Compression.FileSystem
27+
28+
Remove-Item "*.zip"
29+
2730
if ((Test-Path -Path "C:\maven" )) {
2831
Remove-Item -Recurse -Force "C:\maven"
2932
}
30-
31-
(new-object System.Net.WebClient).DownloadFile(
32-
'https://dlcdn.apache.org/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.zip',
33-
'C:\maven-bin.zip'
34-
)
35-
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
36-
37-
if (!(Test-Path -Path "C:\sonar-scanner" )) {
38-
(new-object System.Net.WebClient).DownloadFile(
39-
'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip',
40-
'C:\sonar-scanner-dist.zip'
41-
)
42-
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonar-scanner-dist.zip", "C:\sonar-scanner")
33+
if ((Test-Path -Path "C:\maven" )) {
34+
Remove-Item -Recurse -Force "C:\sonar-scanner"
4335
}
44-
if (!(Test-Path -Path "C:\sonarqube" )) {
45-
(new-object System.Net.WebClient).DownloadFile(
46-
'https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.2.46101.zip',
47-
'C:\sonarqube-8.9.2.46101.zip'
48-
)
49-
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonarqube-8.9.2.46101.zip", "C:\sonarqube")
36+
if ((Test-Path -Path "C:\maven" )) {
37+
Remove-Item -Recurse -Force "C:\sonarqube"
5038
}
39+
40+
- curl -fsSL -o C:/maven-bin.zip https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.zip
41+
- curl -fsSL -o C:/sonar-scanner-dist.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip
42+
- curl -fsSL -o C:/sonarqube.zip https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.7.52159.zip
43+
44+
- ps: |
45+
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
46+
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonar-scanner-dist.zip", "C:\sonar-scanner")
47+
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonarqube.zip", "C:\sonarqube")
48+
5149
- ps: |
5250
If ($env:Platform -Match "x86") {
5351
$env:PCRE_PLATFORM="Win32"
@@ -62,10 +60,10 @@ install:
6260
$env:VCVARS_PLATFORM="amd64"
6361
$env:LANG_PLATFORM="-x64"
6462
}
65-
- cmd: SET PATH=C:\maven\apache-maven-3.8.3\bin;%JAVA_HOME%\bin;C:\sonar-scanner\sonar-scanner-4.6.2.2472\bin;%PATH%
66-
- cmd: SET M2_HOME=C:\maven\apache-maven-3.8.3
67-
- cmd: SET MAVEN_HOME=C:\maven\apache-maven-3.8.3
68-
- cmd: SET SONARHOME=C:\sonarqube\sonarqube-8.9.2.46101
63+
- cmd: SET PATH=C:\maven\apache-maven-3.8.4\bin;%JAVA_HOME%\bin;C:\sonar-scanner\sonar-scanner-4.6.2.2472\bin;%PATH%
64+
- cmd: SET M2_HOME=C:\maven\apache-maven-3.8.4
65+
- cmd: SET MAVEN_HOME=C:\maven\apache-maven-3.8.4
66+
- cmd: SET SONARHOME=C:\sonarqube\sonarqube-8.9.7.52159
6967
- cmd: SET TestDataFolder=C:\projects\sonar-cxx\integration-tests\testdata
7068
- cmd: SET
7169

@@ -107,4 +105,4 @@ on_failure:
107105
- ps: Get-ChildItem cxx-checks\target\surefire-reports\*.txt | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
108106
- ps: Get-ChildItem sonar-cxx-plugin\target\surefire-reports\*.txt | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
109107
- ps: Get-ChildItem *.log | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
110-
- ps: Get-ChildItem C:\sonarqube\sonarqube-8.9.2.46101\logs\* | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
108+
- ps: Get-ChildItem C:\sonarqube\sonarqube-8.9.7.52159\logs\* | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,8 @@ private static void templates(LexerfulGrammarBuilder b) {
21852185
b.sequence(b.optional(IDENTIFIER), "=", typeId), // C++
21862186
// syntax sugar to handle type traits providing type name (e.g. std::enable_if_t<>=0, std::enable_if_t<>*=nullptr)
21872187
b.sequence(b.optional("*"), "=", LITERAL),
2188+
// syntax sugar in case type is an identifier, e.g. 'size_t s = 0' (PEG conflict with parameterDeclaration)
2189+
b.sequence(IDENTIFIER, "=", initializerClause),
21882190
b.sequence(b.optional("..."), b.optional(IDENTIFIER)) // C++ (PEG: different order)
21892191
)
21902192
)

cxx-squid/src/test/java/org/sonar/cxx/parser/TemplatesTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ public void templateHead() {
7171
public void templateHead_reallife() {
7272
setRootRule(CxxGrammarImpl.templateHead);
7373

74-
assertThatParser().matches("template<typename T> requires Addable<T>");
74+
assertThatParser()
75+
.matches("template<typename T> requires Addable<T>")
76+
// issue #2317
77+
.matches("template <typename T, size_t s = sizeof(T)*2 >")
78+
.matches("template <typename T, size_t s = 1>2 >");
7579
}
7680

7781
@Test
@@ -126,7 +130,12 @@ public void templateParameter_reallife() {
126130
.matches("template<typename = float> typename = foo::foo")
127131
// parameter-declaration
128132
.matches("auto ... vs")
129-
.matches("auto** pp0");
133+
.matches("auto** pp0")
134+
// issue #2317
135+
.matches("size_t s = 15")
136+
.matches("size_t s = sizeof(T)*2")
137+
.matches("values v = v::ok")
138+
.matches("T::type n = 0");
130139
}
131140

132141
@Test

0 commit comments

Comments
 (0)