summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test/staticconstfield.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/test/staticconstfield.cxx')
-rw-r--r--compilerplugins/clang/test/staticconstfield.cxx71
1 files changed, 69 insertions, 2 deletions
diff --git a/compilerplugins/clang/test/staticconstfield.cxx b/compilerplugins/clang/test/staticconstfield.cxx
index 49b326f7d76e..03708fcaa9fd 100644
--- a/compilerplugins/clang/test/staticconstfield.cxx
+++ b/compilerplugins/clang/test/staticconstfield.cxx
@@ -15,7 +15,7 @@ class Class1
OUString const m_field1; // expected-note {{field here [loplugin:staticconstfield]}}
Class1()
: m_field1("xxxx")
- // expected-error@-1 {{string field can be static const [loplugin:staticconstfield]}}
+ // expected-error@-1 {{field can be static const [loplugin:staticconstfield]}}
{
(void)m_field1;
}
@@ -26,7 +26,7 @@ class Class2
OString const m_field1; // expected-note {{field here [loplugin:staticconstfield]}}
Class2()
: m_field1("xxxx")
- // expected-error@-1 {{string field can be static const [loplugin:staticconstfield]}}
+ // expected-error@-1 {{field can be static const [loplugin:staticconstfield]}}
{
(void)m_field1;
}
@@ -43,4 +43,71 @@ class Class4
}
};
+class Class5
+{
+ enum class Enum
+ {
+ ONE
+ };
+ float const m_field1; // expected-note {{field here [loplugin:staticconstfield]}}
+ int const m_field2; // expected-note {{field here [loplugin:staticconstfield]}}
+ bool const m_field3; // expected-note {{field here [loplugin:staticconstfield]}}
+ Enum const m_field4; // expected-note {{field here [loplugin:staticconstfield]}}
+ Class5()
+ : m_field1(1.0)
+ // expected-error@-1 {{field can be static const [loplugin:staticconstfield]}}
+ , m_field2(1)
+ // expected-error@-1 {{field can be static const [loplugin:staticconstfield]}}
+ , m_field3(true)
+ // expected-error@-1 {{field can be static const [loplugin:staticconstfield]}}
+ , m_field4(Enum::ONE)
+ // expected-error@-1 {{field can be static const [loplugin:staticconstfield]}}
+ {
+ (void)m_field1;
+ (void)m_field2;
+ (void)m_field3;
+ (void)m_field4;
+ }
+};
+
+// no warning expected
+class Class6
+{
+ enum class Enum
+ {
+ ONE
+ };
+ float m_field1;
+ int m_field2;
+ bool m_field3;
+ Enum m_field4;
+ Class6()
+ : m_field1(1.0)
+ , m_field2(1)
+ , m_field3(true)
+ , m_field4(Enum::ONE)
+ {
+ (void)m_field1;
+ (void)m_field2;
+ (void)m_field3;
+ (void)m_field4;
+ }
+};
+
+// no warning expected, checking for assigning to const field from multiple constructors
+class Class7
+{
+ bool const m_field1;
+ Class7()
+ : m_field1(true)
+ {
+ (void)m_field1;
+ }
+ Class7(bool b)
+ : m_field1(b)
+ {
+ (void)m_field1;
+ }
+};
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */