diff options
author | Anders Carlsson <andersca@mac.com> | 2010-01-24 16:49:46 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-01-24 16:49:46 +0000 |
commit | 77babdb99a99cfe4095d81b72e4bfd304e65ebc7 (patch) | |
tree | ec33ca0b9b8ccf95955f48be40cf8d1877890d85 /clang | |
parent | 20a2c618f296331beb0bd98a7baaca433d1c33f2 (diff) | |
download | bcm5719-llvm-77babdb99a99cfe4095d81b72e4bfd304e65ebc7.tar.gz bcm5719-llvm-77babdb99a99cfe4095d81b72e4bfd304e65ebc7.zip |
Implement [dcl.fct.spec]p6.
llvm-svn: 94365
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 22 | ||||
-rw-r--r-- | clang/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp | 9 |
3 files changed, 34 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index aec03f705a4..5f1e5f16e38 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -446,10 +446,14 @@ def err_mutable_nonmember : Error< "'mutable' can only be applied to member variables">; def err_virtual_non_function : Error< "'virtual' can only appear on non-static member functions">; -def err_explicit_non_function : Error< - "'explicit' can only appear on non-static member functions">; def err_virtual_out_of_class : Error< "'virtual' can only be specified inside the class definition">; +def err_explicit_non_function : Error< + "'explicit' can only appear on non-static member functions">; +def err_explicit_out_of_class : Error< + "'explicit' can only be specified inside the class definition">; +def err_explicit_non_ctor_or_conv_function : Error< + "'explicit' can only be applied to a constructor or conversion function">; def err_static_not_bitfield : Error<"static member %0 cannot be a bit-field">; def err_static_out_of_line : Error< "'static' can only be specified inside the class definition">; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fbe02894ace..938c41efbe6 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2783,6 +2783,28 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, } } + // C++ [dcl.fct.spec]p6: + // The explicit specifier shall be used only in the declaration of a + // constructor or conversion function within its class definition; see 12.3.1 + // and 12.3.2. + if (isExplicit && !NewFD->isInvalidDecl()) { + if (!CurContext->isRecord()) { + // 'explicit' was specified outside of the class. + Diag(D.getDeclSpec().getExplicitSpecLoc(), + diag::err_explicit_out_of_class) + << CodeModificationHint::CreateRemoval( + D.getDeclSpec().getExplicitSpecLoc()); + } else if (!isa<CXXConstructorDecl>(NewFD) && + !isa<CXXConversionDecl>(NewFD)) { + // 'explicit' was specified on a function that wasn't a constructor + // or conversion function. + Diag(D.getDeclSpec().getExplicitSpecLoc(), + diag::err_explicit_non_ctor_or_conv_function) + << CodeModificationHint::CreateRemoval( + D.getDeclSpec().getExplicitSpecLoc()); + } + } + // Filter out previous declarations that don't match the scope. FilterLookupForScope(*this, Previous, DC, S, NewFD->hasLinkage()); diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp index 16a09d836d1..fcc1334b150 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p6.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -verify %s -// XFAIL: * class A { public: @@ -7,7 +6,11 @@ public: explicit operator int(); // expected-warning {{explicit conversion functions are a C++0x extension}} - explicit void f0(); // expected-error {{'explicit' cannot only be applied to constructor or conversion function}} + explicit void f0(); // expected-error {{'explicit' can only be applied to a constructor or conversion function}} + + operator bool(); }; -explicit A::A() { } // expected-error {{'explicit' cannot be specified outside class definition}} +explicit A::A() { } // expected-error {{'explicit' can only be specified inside the class definition}} +explicit A::operator bool() { return false; } // expected-warning {{explicit conversion functions are a C++0x extension}}\ + // expected-error {{'explicit' can only be specified inside the class definition}} |