Constant determinant adopted in ctor declaration / definition (llvm bug?)

My compiler (actually Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)) accepts (compiles) this code:

class X {
private:
  int i;
public:
  const X() { cout << "here" << endl; i=0; }
  void f() const {}
  void g() {}
};

int main() {
  const X x;
  x.f();
  //  x.g();
  X y;
  y.f();
  y.g();
}

It works as if there is no qualifier constdefining the definition of ctor. I tried -Wall, -pedanticvarious standard activations are always the same ... So:

  • Did I miss something? I could not find that it is syntactically correct in the latest standard ...
  • Is this a gcc / llvm error? It seems to gcc/llvmsilently ignore const.
  • Is this a function that I missed and for which my example is not able to demonstrate its usefulness?

Note: gcc 3.4.3 does not compile it, but gcc 4.4.5.

+4
1

, , ++ 12.1 , 1, :

. . :

- spec-specifier-seq, spec- , constexpr,

     

-

     

-

7.1.2 :

function-specifier:
 inline
 virtual
 explicit

Ali .

+3

All Articles