Bug 67038 - [c++-concepts] Viable function template despite unsatisfied constraints
Summary: [c++-concepts] Viable function template despite unsatisfied constraints
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: c++-concepts
: P3 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-27 23:02 UTC by Casey Carter
Modified: 2015-07-30 03:29 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Preprocessed test case (100.12 KB, text/plain)
2015-07-27 23:02 UTC, Casey Carter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Casey Carter 2015-07-27 23:02:57 UTC
Created attachment 36077 [details]
Preprocessed test case

r226205 fails to compile this correct program:

#include <stl2/iterator.hpp>

template <stl2::WeakOutputIterator<int> I>
  requires !stl2::WeakInputIterator<I>()
constexpr bool dispatch() { return false; }

template <stl2::WeakInputIterator I>
constexpr bool dispatch() { return true; }

template <stl2::WeakOutputIterator<int> I>
constexpr bool is_weak_out() { return true; }

template <stl2::WeakInputIterator I>
constexpr bool is_weak_in() { return true; }

int main() {
  static_assert(is_weak_out<int*>());
  static_assert(is_weak_in<int*>());
  static_assert(dispatch<int*>());
}

with error:

~/concept-gcc/bin/g++ -std=gnu++1z -I ~/cmcstl2/include -I ~/cmcstl2/meta/include foo.cpp -c
foo.cpp: In function ‘int main()’:
foo.cpp:19:32: error: call of overloaded ‘dispatch()’ is ambiguous
   static_assert(dispatch<int*>());
                                ^
foo.cpp:5:16: note: candidate: constexpr bool dispatch() [with I = int*]
 constexpr bool dispatch() { return false; }
                ^
foo.cpp:8:16: note: candidate: constexpr bool dispatch() [with I = int*]
 constexpr bool dispatch() { return true; }
                ^

The compiler apparently considers both overloads of dispatch to be viable despite that the first overload's constraint !stl2::WeakInputIterator<I>() is clearly not satisfied when I is int*.
Comment 1 Jason Merrill 2015-07-30 03:29:24 UTC
Fixed.
Comment 2 Jason Merrill 2015-07-30 03:29:32 UTC
Author: jason
Date: Thu Jul 30 03:29:00 2015
New Revision: 226380

URL: https://gcc.gnu.org/viewcvs?rev=226380&root=gcc&view=rev
Log:
	PR c++/67038
	* constraint.cc (satisfy_constraint): Use dummy args if null.

Added:
    branches/c++-concepts/gcc/testsuite/g++.dg/concepts/req18.C
Modified:
    branches/c++-concepts/ChangeLog.concepts
    branches/c++-concepts/gcc/cp/constraint.cc