-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing error when using template type parameter with assignment #2317
Comments
Hello @slnj, will have a look to it. For your explanation: General problem is that the cxx plugin is only parsing the grammar (syntax analysis) without knowing the semantic. Below is a good sample: First case works because template < typename T, int s = 15 > void f(){} // works: int is integral type
template < typename T, size_t s = 15 > void f(){} // fails Our second problem is that we are using SonarSource Language Recognizer (SSLR) which implements PEG parsing. Syntactically, PEGs also look similar to context-free grammars (CFGs), but they have a different interpretation: the choice operator selects the first match in PEG, while it is ambiguous in CFG. That means we have to change the order of the rules in the grammar in some places. This is ultimately a lot of "try and error", especially in such a complex grammar as C++. Regards, |
- close SonarOpenCommunity#2317 There is a PEG issue with the order of ``` template-parameter: type-parameter parameter-declaration ``` `type-parameter type-constraint' rule matches in case of non integral data type. Samples: ```C++ template <typename T, size_t s = 15 > void f() {} template <typename T, size_t s = sizeof(T)*2 > void f() {} template <typename T, size_t s = 1>2 > void f() {} template <values v = v::ok> void f() {} template<class T, T::type n = 0> class X; ```
- update to SQ 8.9.7.52159 for testing - close SonarOpenCommunity#2317 There is a PEG issue with the order of ``` template-parameter: type-parameter parameter-declaration ``` `type-parameter type-constraint' rule matches in case of non integral data type. Samples: ```C++ template <typename T, size_t s = 15 > void f() {} template <typename T, size_t s = sizeof(T)*2 > void f() {} template <typename T, size_t s = 1>2 > void f() {} template <values v = v::ok> void f() {} template<class T, T::type n = 0> class X; ```
- update to SQ 8.9.7.52159 for testing - use Start-FileDownload in AppVeyor - close SonarOpenCommunity#2317 There is a PEG issue with the order of ``` template-parameter: type-parameter parameter-declaration ``` `type-parameter type-constraint' rule matches in case of non integral data type. Samples: ```C++ template <typename T, size_t s = 15 > void f() {} template <typename T, size_t s = sizeof(T)*2 > void f() {} template <typename T, size_t s = 1>2 > void f() {} template <values v = v::ok> void f() {} template<class T, T::type n = 0> class X; ```
- update to SQ 8.9.7.52159 for testing - update to Maven 3.8.4 - use Start-FileDownload in AppVeyor - close SonarOpenCommunity#2317 There is a PEG issue with the order of ``` template-parameter: type-parameter parameter-declaration ``` `type-parameter type-constraint' rule matches in case of non integral data type. Samples: ```C++ template <typename T, size_t s = 15 > void f() {} template <typename T, size_t s = sizeof(T)*2 > void f() {} template <typename T, size_t s = 1>2 > void f() {} template <values v = v::ok> void f() {} template<class T, T::type n = 0> class X; ```
- update to SQ 8.9.7.52159 for testing - update to Maven 3.8.4 - use curl in AppVeyor - close SonarOpenCommunity#2317 There is a PEG issue with the order of ``` template-parameter: type-parameter parameter-declaration ``` `type-parameter type-constraint' rule matches in case of non integral data type. Samples: ```C++ template <typename T, size_t s = 15 > void f() {} template <typename T, size_t s = sizeof(T)*2 > void f() {} template <typename T, size_t s = 1>2 > void f() {} template <values v = v::ok> void f() {} template<class T, T::type n = 0> class X; ```
- update to SQ 8.9.7.52159 for testing - update to Maven 3.8.4 - use curl in AppVeyor - close SonarOpenCommunity#2317 There is a PEG issue with the order of ``` template-parameter: type-parameter parameter-declaration ``` `type-parameter type-constraint' rule matches in case of non integral data type. Samples: ```C++ template <typename T, size_t s = 15 > void f() {} template <typename T, size_t s = sizeof(T)*2 > void f() {} template <typename T, size_t s = 1>2 > void f() {} template <values v = v::ok> void f() {} template<class T, T::type n = 0> class X; ```
- update to SQ 8.9.7.52159 for testing - update to Maven 3.8.4 - use curl in AppVeyor - close SonarOpenCommunity#2317 There is a PEG issue with the order of ``` template-parameter: type-parameter parameter-declaration ``` `type-parameter type-constraint' rule matches in case of non integral data type. Samples: ```C++ template <typename T, size_t s = 15 > void f() {} template <typename T, size_t s = sizeof(T)*2 > void f() {} template <typename T, size_t s = 1>2 > void f() {} template <values v = v::ok> void f() {} template<class T, T::type n = 0> class X; ```
Hello!
When using a template parameter with regular type parameters with default value assignment, a parsing error is reported.
This cases are valid and generate parsing errors:
The type could be:
integral type
enumerator
lvalue reference
nullptr
pointer
An a default value could be assigned
Also, the default value could be an expression like: (sizeof(T)*2)
Regards
The text was updated successfully, but these errors were encountered: