When reporting on mismatching template types, the C++ compiler will
now use color to highlight the mismatching parts of the template, and will
elide the parameters that are common between two mismatching templates,
printing [...] instead:
$ gcc templates.cc
templates.cc: In function 'void test()':
templates.cc:9:8: error: could not convert 'vector<double>()' from 'vector<double>' to 'vector<int>'
fn_1(vector<double> ());
^~~~~~~~~~~~~~~~~
templates.cc:10:8: error: could not convert 'map<int, double>()' from 'map<[...],double>' to 'map<[...],int>'
fn_2(map<int, double>());
^~~~~~~~~~~~~~~~~~
Those [...] elided parameters can be seen using
-fno-elide-type:
$ gcc templates.cc -fno-elide-type
templates.cc: In function 'void test()':
templates.cc:9:8: error: could not convert 'vector<double>()' from 'vector<double>' to 'vector<int>'
fn_1(vector<double> ());
^~~~~~~~~~~~~~~~~
templates.cc:10:8: error: could not convert 'map<int, double>()' from 'map<int,double>' to 'map<int,int>'
fn_2(map<int, double>());
^~~~~~~~~~~~~~~~~~
The C++ compiler has also gained an option
-fdiagnostics-show-template-tree which visualizes such
mismatching templates in a hierarchical form:
$ gcc templates-2.cc -fdiagnostics-show-template-tree
templates-2.cc: In function 'void test()':
templates-2.cc:9:8: error: could not convert 'vector<double>()' from 'vector<double>' to 'vector<int>'
vector<
[double != int]>
fn_1(vector<double> ());
^~~~~~~~~~~~~~~~~
templates-2.cc:10:8: error: could not convert 'map<map<int, vector<double> >, vector<double> >()' from 'map<map<[...],vector<double>>,vector<double>>' to 'map<map<[...],vector<float>>,vector<float>>'
map<
map<
[...],
vector<
[double != float]>>,
vector<
[double != float]>>
fn_2(map<map<int, vector<double>>, vector<double>> ());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
which again works with -fno-elide-type:
$ gcc templates-2.cc -fdiagnostics-show-template-tree -fno-elide-type
templates-2.cc: In function 'void test()':
templates-2.cc:9:8: error: could not convert 'vector<double>()' from 'vector<double>' to 'vector<int>'
vector<
[double != int]>
fn_1(vector<double> ());
^~~~~~~~~~~~~~~~~
templates-2.cc:10:8: error: could not convert 'map<map<int, vector<double> >, vector<double> >()' from 'map<map<int,vector<double>>,vector<double>>' to 'map<map<int,vector<float>>,vector<float>>'
map<
map<
int,
vector<
[double != float]>>,
vector<
[double != float]>>
fn_2(map<map<int, vector<double>>, vector<double>> ());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~