[PATCH] D144626: [C++20] [Modules] Provide OriginalTrailingRequiresClause for serializer to perform ODR-Checking correctly

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 23 01:52:03 PST 2023


ChuanqiXu created this revision.
ChuanqiXu added reviewers: erichkeane, cor3ntin, royjacobson, clang-language-wg.
ChuanqiXu added a project: clang-modules.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Close https://github.com/llvm/llvm-project/issues/60890.

For the following example:

  cpp
  export module a;
   
  export template<typename T>
  struct a {
  	friend void aa(a) requires(true) {
  	}
  };



  cpp
  export module b;
  
  import a;
  
  struct b {
  	a<int> m;
  };



  cpp
  export module c;
  
  import a;
  
  struct c {
  	void f() const {
  		aa(a<int>());
  	}
  };



  cpp
  import a;
  import b;
  import c;
  
  void d() {
  	aa(a<int>());
  }

The current clang will reject this incorrectly. The reason is that the require clause  will be replaced with the evaluated version (https://github.com/llvm/llvm-project/blob/efae3174f09560353fb0f3d528bcbffe060d5438/clang/lib/Sema/SemaConcept.cpp#L664-L665). In module 'b', the friend function is instantiated but not used so the require clause of the friend function is `(true)`. However, in module 'c', the friend function is used so the require clause is `true`. So deserializer classify these two function to two different functions instead of one. Then here is the bug report.

The proposed solution is to provide an original require clause which wouldn't change during the semantic analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144626

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/pr60890.cppm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144626.499770.patch
Type: text/x-patch
Size: 4561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230223/0ed13acf/attachment.bin>


More information about the cfe-commits mailing list