Fix issue 1661: Flags argument silently ignored in re functions with compiled regexes.
diff --git a/Lib/re.py b/Lib/re.py
index a33e34e..39e81fd 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -224,6 +224,8 @@
         return p
     pattern, flags = key
     if isinstance(pattern, _pattern_type):
+        if flags:
+            raise ValueError('Cannot process flags argument with a compiled pattern')
         return pattern
     if not sre_compile.isstring(pattern):
         raise TypeError, "first argument must be string or compiled pattern"