diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index a25d59fa77b031b805da10ee87c3aa682603e31f..f3e3e9ba0a5116752fcdc42a3b43887d6f519097 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -3308,6 +3308,8 @@ pointer_int_sum (location_t loc, enum tree_code resultcode, size_exp = integer_one_node; else { + if (!complain && !COMPLETE_TYPE_P (TREE_TYPE (result_type))) + return error_mark_node; size_exp = size_in_bytes_loc (loc, TREE_TYPE (result_type)); /* Wrap the pointer expression in a SAVE_EXPR to make sure it is evaluated first when the size expression may depend diff --git a/gcc/testsuite/g++.dg/template/sfinae32.C b/gcc/testsuite/g++.dg/template/sfinae32.C new file mode 100644 index 0000000000000000000000000000000000000000..ae1dadaacc4fb2e0dc094eec9b27d2d246b324a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/sfinae32.C @@ -0,0 +1,24 @@ +// PR c++/103700 +// { dg-do compile { target c++11 } } + +template<class T, int N> auto f(T* p) -> decltype(p + N); +template<class T, int N> auto f(T* p) -> decltype(p - N); +template<class T, int N> auto f(T* p) -> decltype(N + p); +template<class T, int N> void f(T* p); + +template<class T> auto g(T* p, int n) -> decltype(p + n); +template<class T> auto g(T* p, int n) -> decltype(p - n); +template<class T> auto g(T* p, int n) -> decltype(n + p); +template<class T> void g(T* p, int n); + +struct Incomplete; + +int main() { + f<Incomplete, 0>(nullptr); + f<Incomplete, 1>(nullptr); + f<Incomplete, -1>(nullptr); + f<Incomplete, 7>(nullptr); + f<Incomplete, -7>(nullptr); + + g<Incomplete>(nullptr, 0); +}