Commits

George Russell committed 5be2f17

Add test dir missed in patch

  • Participants
  • Parent commits 23a159a

Comments (0)

Files changed (1)

File tools/clang/test/SemaConstByDefault/negative_test.cpp

+// RUN: %clang_cc1 -fconstbydefault -fsyntax-only -verify %s
+
+void f() 
+{
+    int x = 0;   
+    x = 1; // expected-error {{read-only variable is not assignable}}
+    mutable int x2;
+    x2 = 0;
+    mutable int x3 = 0;
+    x3 = 1;
+    int x4; // expected-error{{default initialization of an object of const type 'const int'}}
+}
+
+int f2(mutable int* p)
+{
+    *p += 1;
+    return *p;
+}
+
+int f2(int* p)
+{
+    *p += 1; // expected-error {{read-only variable is not assignable}}
+    return *p;
+}
+
+struct xxx {
+    mutable int a;
+    int b;
+    
+    void fMutable() mutable {} // expected-note {{'fMutable' declared here}}
+    void fNotMutable()  {}
+    
+    xxx() : b(10) {}
+    ~xxx() {}
+};
+
+void t() {
+    xxx v;
+    v.b = 111; // expected-error {{read-only variable is not assignable}}
+    v.a = 222;
+    
+    mutable xxx v2;
+    v2.b = 111; // expected-error {{read-only variable is not assignable}}
+    v2.a = 222;
+    v2.fMutable();
+    v2.fNotMutable();
+    
+    v.fMutable(); // expected-error {{member function 'fMutable' not viable: 'this' argument has type 'const xxx', but function is not marked const}}
+    v.fNotMutable();
+    xxx v3( v );
+}