Skip to content

Commit

Permalink
Merge pull request #2321 from guwirth/fix-2317
Browse files Browse the repository at this point in the history
Parsing error when using template type parameter with assignment
  • Loading branch information
guwirth authored Feb 24, 2022
2 parents 85522b0 + 246beca commit e6a5f9e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jdk:
- openjdk11
env:
- SONARLABEL=sonarqube-7.9.6 SONARAPI=SqApi79
- SONARLABEL=sonarqube-8.9.2.46101 SONARAPI=SqApi79
- SONARLABEL=sonarqube-8.9.7.52159 SONARAPI=SqApi79

addons:
# shorten the VM hostname with the new workaround
Expand Down
46 changes: 22 additions & 24 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,28 @@ cache:
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
Remove-Item "*.zip"
if ((Test-Path -Path "C:\maven" )) {
Remove-Item -Recurse -Force "C:\maven"
}
(new-object System.Net.WebClient).DownloadFile(
'https://dlcdn.apache.org/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.zip',
'C:\maven-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
if (!(Test-Path -Path "C:\sonar-scanner" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip',
'C:\sonar-scanner-dist.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonar-scanner-dist.zip", "C:\sonar-scanner")
if ((Test-Path -Path "C:\maven" )) {
Remove-Item -Recurse -Force "C:\sonar-scanner"
}
if (!(Test-Path -Path "C:\sonarqube" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.2.46101.zip',
'C:\sonarqube-8.9.2.46101.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonarqube-8.9.2.46101.zip", "C:\sonarqube")
if ((Test-Path -Path "C:\maven" )) {
Remove-Item -Recurse -Force "C:\sonarqube"
}
- 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
- curl -fsSL -o C:/sonar-scanner-dist.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip
- curl -fsSL -o C:/sonarqube.zip https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.7.52159.zip

- ps: |
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonar-scanner-dist.zip", "C:\sonar-scanner")
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonarqube.zip", "C:\sonarqube")
- ps: |
If ($env:Platform -Match "x86") {
$env:PCRE_PLATFORM="Win32"
Expand All @@ -62,10 +60,10 @@ install:
$env:VCVARS_PLATFORM="amd64"
$env:LANG_PLATFORM="-x64"
}
- 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%
- cmd: SET M2_HOME=C:\maven\apache-maven-3.8.3
- cmd: SET MAVEN_HOME=C:\maven\apache-maven-3.8.3
- cmd: SET SONARHOME=C:\sonarqube\sonarqube-8.9.2.46101
- 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%
- cmd: SET M2_HOME=C:\maven\apache-maven-3.8.4
- cmd: SET MAVEN_HOME=C:\maven\apache-maven-3.8.4
- cmd: SET SONARHOME=C:\sonarqube\sonarqube-8.9.7.52159
- cmd: SET TestDataFolder=C:\projects\sonar-cxx\integration-tests\testdata
- cmd: SET

Expand Down Expand Up @@ -107,4 +105,4 @@ on_failure:
- ps: Get-ChildItem cxx-checks\target\surefire-reports\*.txt | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem sonar-cxx-plugin\target\surefire-reports\*.txt | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem *.log | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem C:\sonarqube\sonarqube-8.9.2.46101\logs\* | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem C:\sonarqube\sonarqube-8.9.7.52159\logs\* | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,8 @@ private static void templates(LexerfulGrammarBuilder b) {
b.sequence(b.optional(IDENTIFIER), "=", typeId), // C++
// syntax sugar to handle type traits providing type name (e.g. std::enable_if_t<>=0, std::enable_if_t<>*=nullptr)
b.sequence(b.optional("*"), "=", LITERAL),
// syntax sugar in case type is an identifier, e.g. 'size_t s = 0' (PEG conflict with parameterDeclaration)
b.sequence(IDENTIFIER, "=", initializerClause),
b.sequence(b.optional("..."), b.optional(IDENTIFIER)) // C++ (PEG: different order)
)
)
Expand Down
13 changes: 11 additions & 2 deletions cxx-squid/src/test/java/org/sonar/cxx/parser/TemplatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ public void templateHead() {
public void templateHead_reallife() {
setRootRule(CxxGrammarImpl.templateHead);

assertThatParser().matches("template<typename T> requires Addable<T>");
assertThatParser()
.matches("template<typename T> requires Addable<T>")
// issue #2317
.matches("template <typename T, size_t s = sizeof(T)*2 >")
.matches("template <typename T, size_t s = 1>2 >");
}

@Test
Expand Down Expand Up @@ -126,7 +130,12 @@ public void templateParameter_reallife() {
.matches("template<typename = float> typename = foo::foo")
// parameter-declaration
.matches("auto ... vs")
.matches("auto** pp0");
.matches("auto** pp0")
// issue #2317
.matches("size_t s = 15")
.matches("size_t s = sizeof(T)*2")
.matches("values v = v::ok")
.matches("T::type n = 0");
}

@Test
Expand Down

0 comments on commit e6a5f9e

Please sign in to comment.