This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch THRIFT-5835
in repository https://gitbox.apache.org/repos/asf/thrift.git

commit c9ffe934fc6fe5ce9f1cb84c0ebf75eb21133d19
Author: Jens Geyer <[email protected]>
AuthorDate: Tue Nov 19 01:16:07 2024 +0100

    exceptionstruct bremse raus
---
 compiler/cpp/src/thrift/parse/t_function.h | 6 ++++++
 compiler/cpp/src/thrift/parse/t_list.h     | 2 ++
 compiler/cpp/src/thrift/parse/t_map.h      | 2 ++
 compiler/cpp/src/thrift/parse/t_set.h      | 2 ++
 compiler/cpp/src/thrift/parse/t_struct.h   | 6 ++++--
 compiler/cpp/src/thrift/parse/t_type.h     | 3 +++
 6 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/compiler/cpp/src/thrift/parse/t_function.h 
b/compiler/cpp/src/thrift/parse/t_function.h
index 57cf5ffce..d2cb19bbc 100644
--- a/compiler/cpp/src/thrift/parse/t_function.h
+++ b/compiler/cpp/src/thrift/parse/t_function.h
@@ -85,17 +85,23 @@ public:
 
   void validate() const {
     get_returntype()->validate();
+
+#ifndef ALLOW_EXCEPTIONS_AS_TYPE
     if (get_returntype()->get_true_type()->is_xception()) {
       failure("method %s(): exception type \"%s\" cannot be used as function 
return", get_name().c_str(), get_returntype()->get_name().c_str());
     }
+#endif
 
     std::vector<t_field*>::const_iterator it;
     std::vector<t_field*> list = get_arglist()->get_members();
     for(it=list.begin(); it != list.end(); ++it) {
       (*it)->get_type()->validate();
+
+#ifndef ALLOW_EXCEPTIONS_AS_TYPE
       if( (*it)->get_type()->get_true_type()->is_xception()) {
         failure("method %s(): exception type \"%s\" cannot be used as function 
argument %s", get_name().c_str(), (*it)->get_type()->get_name().c_str(), 
(*it)->get_name().c_str());
       }
+#endif
     }
   }
 
diff --git a/compiler/cpp/src/thrift/parse/t_list.h 
b/compiler/cpp/src/thrift/parse/t_list.h
index 5daa412bd..162281cc0 100644
--- a/compiler/cpp/src/thrift/parse/t_list.h
+++ b/compiler/cpp/src/thrift/parse/t_list.h
@@ -35,9 +35,11 @@ public:
   bool is_list() const override { return true; }
 
   void validate() const {
+#ifndef ALLOW_EXCEPTIONS_AS_TYPE
     if( get_elem_type()->get_true_type()->is_xception()) {
       failure("exception type \"%s\" cannot be used inside a list", 
get_elem_type()->get_name().c_str());
     }
+#endif
   }
 
 private:
diff --git a/compiler/cpp/src/thrift/parse/t_map.h 
b/compiler/cpp/src/thrift/parse/t_map.h
index 444fca798..30a8b06c9 100644
--- a/compiler/cpp/src/thrift/parse/t_map.h
+++ b/compiler/cpp/src/thrift/parse/t_map.h
@@ -38,12 +38,14 @@ public:
   bool is_map() const override { return true; }
 
   void validate() const {
+#ifndef ALLOW_EXCEPTIONS_AS_TYPE
     if( get_key_type()->get_true_type()->is_xception()) {
       failure("exception type \"%s\" cannot be used inside a map", 
get_key_type()->get_name().c_str());
     }
     if( get_val_type()->get_true_type()->is_xception()) {
       failure("exception type \"%s\" cannot be used inside a map", 
get_val_type()->get_name().c_str());
     }
+#endif
   }
 
 private:
diff --git a/compiler/cpp/src/thrift/parse/t_set.h 
b/compiler/cpp/src/thrift/parse/t_set.h
index 4a02dcc08..88de93f44 100644
--- a/compiler/cpp/src/thrift/parse/t_set.h
+++ b/compiler/cpp/src/thrift/parse/t_set.h
@@ -37,9 +37,11 @@ public:
   bool is_set() const override { return true; }
 
   void validate() const {
+#ifndef ALLOW_EXCEPTIONS_AS_TYPE
     if( get_elem_type()->get_true_type()->is_xception()) {
       failure("exception type \"%s\" cannot be used inside a set", 
get_elem_type()->get_name().c_str());
     }
+#endif
   }
 
 private:
diff --git a/compiler/cpp/src/thrift/parse/t_struct.h 
b/compiler/cpp/src/thrift/parse/t_struct.h
index 941712d80..3aa67c0e1 100644
--- a/compiler/cpp/src/thrift/parse/t_struct.h
+++ b/compiler/cpp/src/thrift/parse/t_struct.h
@@ -112,9 +112,8 @@ public:
   const members_type& get_sorted_members() const { return 
members_in_id_order_; }
 
   bool is_struct() const override { return !is_xception_; }
-
   bool is_xception() const override { return is_xception_; }
-
+  bool is_method_xcepts() const override { return is_method_xcepts_; }
   bool is_union() const { return is_union_; }
 
   t_field* get_field_by_name(std::string field_name) {
@@ -144,11 +143,14 @@ public:
     std::vector<t_field*> list = get_members();
     for(it=list.begin(); it != list.end(); ++it) {
       (*it)->get_type()->validate();
+
+#ifndef ALLOW_EXCEPTIONS_AS_TYPE
       if (!is_method_xcepts_) {  // this is in fact the only legal usage for 
any exception type
         if( (*it)->get_type()->get_true_type()->is_xception()) {
           failure("%s %s: exception type \"%s\" cannot be used as member field 
type %s", what.c_str(), get_name().c_str(), 
(*it)->get_type()->get_name().c_str(), (*it)->get_name().c_str());
         }
       }
+#endif
     }
   }
 
diff --git a/compiler/cpp/src/thrift/parse/t_type.h 
b/compiler/cpp/src/thrift/parse/t_type.h
index f4082426c..d087601ae 100644
--- a/compiler/cpp/src/thrift/parse/t_type.h
+++ b/compiler/cpp/src/thrift/parse/t_type.h
@@ -26,6 +26,8 @@
 #include <stdint.h>
 #include <string>
 
+#define ALLOW_EXCEPTIONS_AS_TYPE
+
 class t_program;
 
 /**
@@ -54,6 +56,7 @@ public:
   virtual bool is_enum() const { return false; }
   virtual bool is_struct() const { return false; }
   virtual bool is_xception() const { return false; }
+  virtual bool is_method_xcepts() const { return false; }
   virtual bool is_container() const { return false; }
   virtual bool is_list() const { return false; }
   virtual bool is_set() const { return false; }

Reply via email to