cconvey commented on code in PR #13267:
URL: https://github.com/apache/tvm/pull/13267#discussion_r1013385933


##########
src/tir/transforms/narrow_datatype.cc:
##########
@@ -187,6 +187,11 @@ class DataTypeVisitor final : public StmtExprVisitor {
   arith::ConstIntBoundAnalyzer::BoundMapType bound_;
 };
 
+#if __clang__

Review Comment:
   Sorry, let me try making my point better with a slightly different example:
   ``` c++
   #include <iostream>
   #include <string>
   using namespace std;
   
   class BaseClass {
      public:
       virtual void foo(int x) {
           cout << "BaseClass::foo(int): x = " << x << endl;
       }
   
       virtual void foo(string x) {
           cout << "BaseClass::foo(string): x = " << x << endl;
       }
   };
   
   class DerivedClass : public BaseClass {
      public:
   #ifdef OVERLOAD_FOO
       virtual void foo(int x) {
            cout << "DerivedClass::foo(int): x = " << x << endl;
       }
   #endif
   };
   
   int main() {
       DerivedClass d;
       d.foo("Hello, TVM!");
   }
   ```
   
   If I compile this with simply `clang++ -Woverloaded-virtual x.cpp`, the 
compilation succeeds.  And when I run the resulting executable, it prints 
`BaseClass::foo(string): x = Hello, TVM!`.
   
   But if I try to compile this with `clang++ -Woverloaded-virtual 
-DOVERLOAD_FOO x.cpp`, I get this error:
   ```
   x.cpp:27:11: error: cannot initialize a parameter of type 'int' with an 
lvalue of type 'const char[12]'
       d.foo("Hello, TVM!");
             ^~~~~~~~~~~~~
   x.cpp:19:26: note: passing argument to parameter 'x' here
       virtual void foo(int x) {
                            ^
   1 error generated.
   ```
    The issue, as I understand it, is that because `DerviedClass` provides 
_even one_ override of a base-class virtual function (`foo`), C++ will no 
longer look at _any_ of the `BaseClass::foo(...)` overloads when it sees a call 
such as `d.foo("Hello, TVM!")` in the example above.
   
   Those base-class functions aren't _completely_ hidden.  For example, if we 
use `d.BaseClass("Hello, TVM!")` instead, the code compiles just fine.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to