[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 14 09:35:13 PST 2024
================
@@ -11322,9 +11322,22 @@ Decl *Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
<< ClassType << ConvType;
}
- if (FunctionTemplateDecl *ConversionTemplate
- = Conversion->getDescribedFunctionTemplate())
+ if (FunctionTemplateDecl *ConversionTemplate =
+ Conversion->getDescribedFunctionTemplate()) {
+ if (ConvType->isUndeducedAutoType()) {
+ Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
+ << Conversion->getTypeSourceInfo()
+ ->getTypeLoc()
+ .getContainedAutoTypeLoc()
+ .getSourceRange()
+ << llvm::to_underlying(Conversion->getConversionType()
+ ->getAs<AutoType>()
+ ->getKeyword())
----------------
cor3ntin wrote:
You do not have to change it here, but this is kind of nasty.
`<< Conversion->getConversionType()` should just work, so this is an artifact of a weirdly constructed diagnostic.
I wonder if we should adapt the `err_auto_not_allowed` diagnostic.
We do this weird dance in 3 places
I also will not properly diagnose constrained return types
ie ```cpp
template <typename T>
concept C = true;
struct S {
operator C auto();
};```
Writing that iI think we should bite the bullet and change it
```cpp
def err_auto_not_allowed : Error<
"%select{"use of "
"%select{class template|function template|variable template|alias template|"
"template template parameter|concept|template}3 %4 requires template "
"arguments; argument deduction|%2}0 not allowed "
"%select{in function prototype"
"|in non-static struct member|in struct member"
"|in non-static union member|in union member"
"|in non-static class member|in interface member"
"|in exception declaration|in template parameter until C++17|in block literal"
"|in template argument|in typedef|in type alias|in function return type"
"|in conversion function type|here|in lambda parameter"
"|in type allocated by 'new'|in K&R-style function parameter"
"|in template parameter|in friend declaration|in function prototype that is "
"not a function declaration|in requires expression parameter"
"|in array declaration"
"|in declaration of conversion function template}1">;
```
Should work, we would have to change the 3 uses of err_auto_not_allowed
Can you add tests for constrained auto?
https://github.com/llvm/llvm-project/pull/78103
More information about the cfe-commits
mailing list