macanjang / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

PrintTo selects default printer when better base class PrintTo exists #443

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm not sure this issues if fixable, but wanted to document it incase someone 
else comes across it.

----------------------------------------------
What steps will reproduce the problem?

1. Compile attachment.
2. Run it.

$ clang++ -DDEBUG printto-example.cpp libgtest.a -lpthread && ./a.out
A is awesome
1-byte object <20>

$ g++ -DDEBUG printto-example.cpp libgtest.a -lpthread && ./a.out
A is awesome
1-byte object <00>

----------------------------------------------
What is the expected output? What do you see instead?

$ ./a.out
A is awesome
A is awesome

----------------------------------------------
Work around?

Create a PrintTo method for all the sub-classes.

----------------------------------------------
Why does this happen?

gtest has the following PrintTo template;
   template <typename T>
   void PrintTo(const T& value, ::std::ostream* os);

This templated PrintTo is specific when the PrintTo which takes the BaseClass.

----------------------------------------------
Possible solution

Use SFINAE to detect if the default PrintTo should be called. Example of how 
this might work is found in the printto-possiblefix.cpp file.

----------------------------------------------
What version of Google Test are you using? On what operating system?

gtest 1.6.0-1ubuntu4, Linux Ubuntu Precise.

ii  clang                                                   3.0-6ubuntu3        
                                Low-Level Virtual Machine (LLVM), C language 
family frontend
ii  clang-format                                            1.191733.53539707   
                                clang-format
ii  clang-tools                                             3.2-1               
                                Clang tools
ii  libclang-common-dev                                     3.0-6ubuntu3        
                                clang library - Common development package
ii  libllvm3.0                                              3.0-4ubuntu1        
                                Low-Level Virtual Machine (LLVM), runtime 
library
ii  libllvm3.0:i386                                         3.0-4ubuntu1        
                                Low-Level Virtual Machine (LLVM), runtime 
library
ii  llvm-3.0                                                3.0-4ubuntu1        
                                Low-Level Virtual Machine (LLVM)
ii  llvm-3.0-dev                                            3.0-4ubuntu1        
                                Low-Level Virtual Machine (LLVM), libraries and 
headers
ii  llvm-3.0-runtime                                        3.0-4ubuntu1        
                                Low-Level Virtual Machine (LLVM), bytecode 
interpreter
ii  gcc-4.6                                                 4.6.3-1ubuntu5      
                                GNU C compiler
ii  gcc-4.6-base                                            4.6.3-1ubuntu5      
                                GCC, the GNU Compiler Collection (base package)
ii  gcc-4.6-base:i386                                       4.6.3-1ubuntu5      
                                GCC, the GNU Compiler Collection (base package)
ii  gcc-4.6-multilib                                        4.6.3-1ubuntu5      
                                GNU C compiler (multilib files)

$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

$ clang --version
Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0)
Target: x86_64-pc-linux-gnu
Thread model: posix

----------------------------------------------

Please provide any additional information below, such as a code snippet.

Original issue reported on code.google.com by mit...@mithis.com on 14 Oct 2013 at 9:35

Attachments: