diff --git a/gcc/cobol/dts.h b/gcc/cobol/dts.h
index 918ed08e1ff9cfccd71520d73cd288f080b4757f..893ef87502b08a29b70d09bf914c0e288bfe4bea 100644
--- a/gcc/cobol/dts.h
+++ b/gcc/cobol/dts.h
@@ -24,6 +24,8 @@
 #include <err.h>
 #include <regex.h>
 
+void yyerrorv( const char fmt[], ... );
+
 namespace dts {
   class csub_match : public regmatch_t {
     const char *input;
@@ -70,12 +72,16 @@ namespace dts {
         throw std::logic_error(msg);
 #else
 	pattern = NULL;
-	warnx("error: %s", msg);
+	yyerrorv("error: %s", msg);
 #endif
       }
     }
+    ~regex() { regfree(this); }
+    
     size_t size() const { return nsubexpr; }
     bool ready() const { return pattern != NULL; }
+  private:
+    regex( const regex& ) {}
   };
 
   inline bool regex_search( const char input[], const char *eoinput,