https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96096

            Bug ID: 96096
           Summary: g++-10.1 silently ignores function violating const
                    instead of refusing to compile
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: agadethrowaway at gmail dot com
  Target Milestone: ---

Created attachment 48842
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48842&action=edit
Minimal bug reproduction code

Attached code compiled with:

g++-10 (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0

with compile line:
g++-10 Const_Violation_Silent_Error.cpp -o Const_Violation_Silent_Error

compiles whereas g++-9 (g++-9 (Ubuntu 9.3.0-11ubuntu0~18.04.1) 9.3.0) correctly
refuses to with error:

error: binding reference of type ‘dummy&’ to ‘const dummy’ discards
qualifiers...

Not only does this code compile when it should not, but it will simply quietly
never enter Modify_Object().

Copy of attached code:

struct dummy{
        int int_param;
};

inline void Modify_Object(dummy &object){
        object.int_param=0;
}

template <bool is_learning=true> void Templated_Function(){
        const dummy R{0};
        Modify_Object(R);
}

int main(){
        Templated_Function();
}

Reply via email to