Unexpected behavior in loop scope

Hello,

I noticed a strange behavior while writing some macro and I don’t know if it is only my lack of C++/CINT experience or an acutal bug.
I found another way to write the macro but for my education I would like to know what is wrong.

I try to use SetPointError() on an object which is either a TGraphErrors or a TGraphAsymmErrors. I check the Object using TObject::IsA().
This example runs fine:

    TGraph *spec = new TGraphErrors;
    //TGraph *spec = new TGraphAsymmErrors;

    if(spec->IsA() == TGraphErrors::Class()){
        TGraphErrors *tmp = static_cast<TGraphErrors*>(spec);
        tmp->SetPointError(0,1,1);
        
    }else if(spec->IsA() == TGraphAsymmErrors::Class()){
        TGraphAsymmErrors *tmp = static_cast<TGraphAsymmErrors*>(spec); //no error 
        tmp->SetPointError(0,2,2,2,2);
    }

However, if I run the same thing inside of a loop (simplified here), CINT will complain.

    TGraph *spec = new TGraphErrors;
    //TGraph *spec = new TGraphAsymmErrors;
    for(;;){
        if(spec->IsA() == TGraphErrors::Class()){
            TGraphErrors *tmp = static_cast<TGraphErrors*>(spec);
            tmp->SetPointError(1,1,1);
            
        }else if(spec->IsA() == TGraphAsymmErrors::Class()){         
            TGraphAsymmErrors *tmp = static_cast<TGraphAsymmErrors*>(spec); 
//Error: tmp already declared as different type test.C:14:
            tmp->SetPointError(1,2,2,2,2);
        }
        break;
    }                  

The condition is not met. Why is an interpreter looking inside?
Also, the scope of tmp is only within the if statement. Why is it visible outside?

I’m using root v5-34-30 on debian wheezy

Hi,

CINT is very powerful but it has some shortcomings, like the one you stumbled in.
All these issues have been solved in the interpreter leveraged by ROOT6, cling.

Cheers,
Danilo