[llvm-bugs] [Bug 47967] New: Template function gets selected also if a non-template function with appropriate signature exists

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 26 02:13:54 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47967

            Bug ID: 47967
           Summary: Template function gets selected also if a non-template
                    function with appropriate signature exists
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andrea_iob at hotmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 24099
  --> https://bugs.llvm.org/attachment.cgi?id=24099&action=edit
Example code that shows the problem.

In the attached example I'm declaring a template stream (<<) operator, then I'm
declaring a non-template operator.

In my understanding the non-template operator should have priority over the
template version. However, there is a case where the template operator is
selected instead of the non-template one. 

When I run the attached example I see the following output:

    # clang++ -o test test.cpp 
    # ./test 
     Using stream operator directly:
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
     Using stream through function 'writeAfter':
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
     Using stream through function 'writeBefore':
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
      > TEMPLATE STREAM OPERATOR

The last call of the function writeBefore is using the template stream operator
instead of the non-template version.

I've tested the example code with clang++ 7.0.1 and 10.0.1 and both give me the
same results.

The "data" and "streamer" namespaces seem to play some role in this behaviour:
if a remove them I get the expected behaviour.

If I compile the example with g++ I get the "correct" output:

    # g++ -o test test.cpp 
    # ./test 
     Using stream operator directly:
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
     Using stream through function 'writeAfter':
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
     Using stream through function 'writeBefore':
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
      > NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData

Let me know if further details are required.
Thanks.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201026/e5c984c6/attachment-0001.html>


More information about the llvm-bugs mailing list