From fe7a9d7856d36de76d8076a03743b1ce6731459c Mon Sep 17 00:00:00 2001
From: "Igor V. Kovalenko" <76685079+i-garrison@users.noreply.github.com>
Date: Sat, 28 Jan 2023 18:54:09 +0300
Subject: [PATCH] Do not allow structured binding initializer referencing
introduced name (#241)
If name lookup ends up with a variable, additionally check if node being
resolved is part of the structured binding initializer introducing found
variable. If this is the case, produce problem binding and report structured
binding declaration error via codan.
This change also prevents infinite recursion trying to resolve auto type of
introduced variable while evaluating such problematic initializer.
---
.../META-INF/MANIFEST.MF | 2 +-
.../OSGI-INF/l10n/bundle.properties | 3 +++
.../org.eclipse.cdt.codan.checkers/plugin.xml | 10 ++++++++++
.../checkers/ProblemBindingChecker.java | 18 ++++++++++++++++++
.../ast2/cxx17/StructuredBindingTests.java | 8 ++++++++
.../cdt/core/dom/ast/IProblemBinding.java | 2 ++
.../cdt/core/dom/ast/ISemanticProblem.java | 2 ++
.../dom/parser/cpp/semantics/CPPSemantics.java | 15 +++++++++++++++
.../internal/core/parser/ParserMessages.java | 2 ++
.../core/parser/ParserMessages.properties | 1 +
10 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF
index bf8136cff1b..5050959033c 100644
--- a/codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.checkers/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.cdt.codan.checkers;singleton:=true
-Bundle-Version: 3.5.0.qualifier
+Bundle-Version: 3.5.100.qualifier
Bundle-Activator: org.eclipse.cdt.codan.checkers.CodanCheckersActivator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
diff --git a/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties b/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties
index 7654d0e4098..15bbc5c8fe0 100644
--- a/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties
+++ b/codan/org.eclipse.cdt.codan.checkers/OSGI-INF/l10n/bundle.properties
@@ -113,6 +113,9 @@ problem.name.11 = Method cannot be resolved
problem.description.12 = Name resolution problem found by the indexer
problem.messagePattern.12 = Field ''{0}'' could not be resolved
problem.name.12 = Field cannot be resolved
+problem.description.13 = Name resolution problem found by the indexer
+problem.messagePattern.13 = Structured binding initializer expression refers to introduced name ''{0}''
+problem.name.13 = Invalid structured binding declaration
checker.name.AbstractClassCreation = Abstract class cannot be instantiated
problem.name.AbstractClassCreation = Abstract class cannot be instantiated
problem.messagePattern.AbstractClassCreation = The type ''{0}'' must implement the inherited pure virtual method ''{1}''\u0020
diff --git a/codan/org.eclipse.cdt.codan.checkers/plugin.xml b/codan/org.eclipse.cdt.codan.checkers/plugin.xml
index 08c0b921af2..7a4d11c604f 100644
--- a/codan/org.eclipse.cdt.codan.checkers/plugin.xml
+++ b/codan/org.eclipse.cdt.codan.checkers/plugin.xml
@@ -273,6 +273,16 @@
messagePattern="%problem.messagePattern.12"
name="%problem.name.12">
+
+