Index: cp/pt.c =================================================================== --- cp/pt.c (revision 203392) +++ cp/pt.c (working copy) @@ -5611,7 +5611,7 @@ convert_nontype_argument (tree type, tree expr, ts TREE_TYPE (TREE_TYPE (addr))))) { expr = TREE_OPERAND (addr, 0); - expr_type = TREE_TYPE (expr); + expr_type = TREE_TYPE (probe_type); } } } Index: testsuite/g++.dg/template/nontype26.C =================================================================== --- testsuite/g++.dg/template/nontype26.C (revision 0) +++ testsuite/g++.dg/template/nontype26.C (working copy) @@ -0,0 +1,20 @@ +// PR c++/31671 + +template void doit() { + i = 0; +} + +template class X { +public: + void foo() { + doit(); // { dg-error "cv-qualification|no matching" } + } +}; + +int i = 0; + +X x; + +int main() { + x.foo(); +}