Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2020-04-01 08:48:25 +0000
committerMarco Stornelli2020-04-06 13:21:36 +0000
commit733d884bc4dd27305c7d91391f7b7cc7564caf91 (patch)
treed7eb86122d3d78e5f0aadc5702e22a5922f02b9d /core/org.eclipse.cdt.core.tests
parent68bb85e4394f066d290c7739aed9c0b8d636f0e2 (diff)
downloadorg.eclipse.cdt-733d884bc4dd27305c7d91391f7b7cc7564caf91.tar.gz
org.eclipse.cdt-733d884bc4dd27305c7d91391f7b7cc7564caf91.tar.xz
org.eclipse.cdt-733d884bc4dd27305c7d91391f7b7cc7564caf91.zip
Bug 534420 - Add support for nodiscard attribute for enum types
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java17
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java11
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.cpp6
3 files changed, 33 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index c7f0d1a7af5..d88aae9b02b 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -13501,4 +13501,21 @@ public class AST2CPPTests extends AST2CPPTestBase {
assertTrue(((CPPClassInstance) var2Spec.getType()).isNoDiscard());
assertTrue(((CPPClassInstance) var3Spec.getType()).isNoDiscard());
}
+
+ // enum [[nodiscard]] hue { red, blue, green };
+ // enum fruit { apple, banana };
+ // enum hue col;
+ // enum fruit f;
+ public void testEnumerations_Bug534420() throws Exception {
+ IASTTranslationUnit tu = parse(getAboveComment(), CPP);
+ NameCollector collector = new NameCollector();
+ tu.accept(collector);
+
+ ICPPEnumeration hue = (ICPPEnumeration) collector.getName(0).resolveBinding();
+ ICPPEnumeration fruit = (ICPPEnumeration) collector.getName(4).resolveBinding();
+ ICPPVariable col = (ICPPVariable) collector.getName(8).resolveBinding();
+ ICPPVariable f = (ICPPVariable) collector.getName(10).resolveBinding();
+ assertTrue(((ICPPEnumeration) col.getType()).isNoDiscard());
+ assertFalse(((ICPPEnumeration) f.getType()).isNoDiscard());
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java
index c5a195530de..abac00004b3 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java
@@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject;
@@ -101,7 +102,8 @@ public class EnumerationTests extends PDOMTestBase {
Pattern pattern = Pattern.compile("TestCPPEnum");
IBinding[] bindings = pdom.findBindings(pattern, false, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bindings.length);
- IEnumeration enumeration = (IEnumeration) bindings[0];
+ ICPPEnumeration enumeration = (ICPPEnumeration) bindings[0];
+ assertFalse(enumeration.isNoDiscard());
assertEquals("TestCPPEnum", enumeration.getName());
IEnumerator[] enumerators = enumeration.getEnumerators();
assertEquals(3, enumerators.length);
@@ -133,5 +135,12 @@ public class EnumerationTests extends PDOMTestBase {
assertEquals(1, aRefs.length);
loc = aRefs[0].getFileLocation();
assertEquals(offset("enumTest.cpp", "cppa;"), loc.getNodeOffset());
+
+ // Check bindings no discard
+ pattern = Pattern.compile("TestCPPEnumNoDis");
+ bindings = pdom.findBindings(pattern, false, IndexFilter.ALL, new NullProgressMonitor());
+ assertEquals(1, bindings.length);
+ enumeration = (ICPPEnumeration) bindings[0];
+ assertTrue(enumeration.isNoDiscard());
}
}
diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.cpp b/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.cpp
index 83d528fd48b..3d470c8d298 100644
--- a/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.cpp
+++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/enumerationTests/enumTest.cpp
@@ -7,3 +7,9 @@ enum TestCPPEnum {
TestCPPEnum test() {
return cppa;
}
+
+enum [[nodiscard]] TestCPPEnumNoDis {
+ e1,
+ e2,
+ e3
+};

Back to the top