Unexpected behaviour in macOS when compiler error in C++ code
When trying to run invalid code in macOS, we obtain a very terse Failed to parse the given C++ code (see screenshot)
whereas same code run in Linux provides the same error line... followed by the appropriate error from the C++ compiler.
@poli and I investigated a bit, and we saw that redirection in macOS is a bit off even when notebook is not involved:
import cppyy
code1 = """
#include <iostream>
#include <tuple>
template <class TupleT>
void PrintSize()
{
std::cout << "Size is " << std::tuple_size<TupleT>() << std::endl;
}
"""
code2 = """
PrintSize<int>();
"""
import sys
sys.stdout = open("stdout.txt", "w")
sys.stderr = open("stderr.txt", "w")
cppyy.cppexec(code1)
cppyy.cppexec(code2)
prints on screen:
input_line_18:8:33: error: implicit instantiation of undefined template 'std::tuple_size<int>'
std::cout << "Size is " << std::tuple_size<TupleT>() << std::endl;
^
input_line_19:3:1: note: in instantiation of function template specialization 'PrintSize<int>' requested here
PrintSize<int>();
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__tuple:24:50: note: template is declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size;
which is clearly not redirected to stdout or stderr.