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


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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to