[cfe-commits] r130057 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/AST/Type.h include/clang/Basic/TokenKinds.def include/clang/Basic/TypeTraits.h lib/AST/DeclCXX.cpp lib/AST/StmtPrinter.cpp lib/AST/Type.cpp lib/Lex/PPMacroExpansion.cpp lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp lib/Parse/ParseTentative.cpp lib/Sema/SemaExprCXX.cpp test/SemaCXX/type-traits.cpp

Douglas Gregor dgregor at apple.com
Sat Apr 23 08:19:27 PDT 2011


On Apr 23, 2011, at 3:47 AM, Chandler Carruth wrote:

> Author: chandlerc
> Date: Sat Apr 23 05:47:28 2011
> New Revision: 130057
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=130057&view=rev
> Log:
> Implement basic __is_trivial type-trait support, enough to close PR9472.
> This introduces a few APIs on the AST to bundle up the standard-based
> logic so that programmatic clients have access to exactly the same
> behavior.

Thanks!

> There is only one serious FIXME here: checking for non-trivial move
> constructors and move assignment operators. Those bits need to be added
> to the declaration and accessors provided.

At the moment, all move constructors and move-assignment operators are non-trivial, since we haven't implemented the implicit declaration or definition of move constructors or move-assignment operators.

> Modified: cfe/trunk/lib/AST/DeclCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=130057&r1=130056&r2=130057&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/DeclCXX.cpp (original)
> +++ cfe/trunk/lib/AST/DeclCXX.cpp Sat Apr 23 05:47:28 2011
> @@ -217,6 +217,23 @@
>   return getCopyConstructor(Context, Qualifiers::Const) != 0;
> }
> 
> +bool CXXRecordDecl::isTriviallyCopyable() const {
> +  // C++0x [class]p5:
> +  //   A trivially copyable class is a class that:
> +  //   -- has no non-trivial copy constructors,
> +  if (!hasTrivialCopyConstructor()) return false;
> +  //   -- has no non-trivial move constructors,
> +  // FIXME: C++0x: Track and check trivial move constructors.
> +  //   -- has no non-trivial copy assignment operators,
> +  if (!hasTrivialCopyAssignment()) return false;
> +  //   -- has no non-trivial move assignment operators, and
> +  // FIXME: C++0x: Track and check trivial move assignment operators.
> +  //   -- has a trivial destructor.
> +  if (!hasTrivialDestructor()) return false;
> +
> +  return true;
> +}

In the near term, the best approach here would be to add and maintain UserDeclaredMoveConstructor and UserDeclaredMoveAssignment bits to CXXRecordDecl::DefinitionData, and have hasTrivialMoveConstructor()/hasTrivialMoveAssignment() just check those. That way, the semantics of __is_trivial will be consistent.

	- Doug




More information about the cfe-commits mailing list