[PATCH] D64321: [OpenCL] Change diagnostic for function declaration

Pierre GONDOIS via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 03:51:14 PDT 2019


Pierre created this revision.
Pierre added reviewers: Anastasia, svenvh.
Pierre added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

When declaring functions only differing by their return type,
diagnostic was indicating "conflicting types for" the function.
Similarly to c++, it is now indicating that "functions that differ
only in their return type cannot be overloaded".

For this code example:

  float test (float p) {return 2.;}
  double test (float p) {return 2.;}

This is changing this diagnostic:

  tmp.cl:5:37: error: conflicting types for 'tee'
  float __attribute__((overloadable)) test (float p) {return 2.;}
                                      ^
  tmp.cl:4:38: note: previous definition is here
  double __attribute__((overloadable)) test (float p) {return 2.;}
                                       ^
  1 error generated.

To this:

  tmp.cl:5:37: error: functions that differ only in their return type cannot be overloaded
  float __attribute__((overloadable)) test (float p) {return 2.;}
  ~~~~~                               ^
  1 error generated.

This should maybe be extended to other languages.


Repository:
  rC Clang

https://reviews.llvm.org/D64321

Files:
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -3466,6 +3466,18 @@
       return false;
 
     // Fall through for conflicting redeclarations and redefinitions.
+  } else if (getLangOpts().OpenCL) {
+    QualType OldDeclaredReturnType = Old->getDeclaredReturnType();
+    QualType NewDeclaredReturnType = New->getDeclaredReturnType();
+
+    if (!Context.hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) &&
+        canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType,
+                                       OldDeclaredReturnType)) {
+
+        Diag(New->getLocation(), diag::err_ovl_diff_return_type)
+            << New->getReturnTypeSourceRange();
+        return true;
+    }
   }
 
   // C: Function types need to be compatible, not identical. This handles


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64321.208360.patch
Type: text/x-patch
Size: 906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190708/df432d83/attachment-0001.bin>


More information about the cfe-commits mailing list